1

Using Macports,

I've tried to install: gdal, py27gdal, and gdal-grass. All so I can import gdal into python 2.7.2.

Neither have been successful.

When I type:

port list installed

I see the installed modules:

gdal-grass                     @1.4.3          gis/gdal-grass   
gdbm                           @1.8.3          databases/gdbm    
py27-gdal                      @1.7.1          python/py27-gdal

And when I run python to import the module:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named gdal

What am I doing wrong?

Artsiom Rudzenka
  • 27,895
  • 4
  • 34
  • 52
Alvin
  • 357
  • 1
  • 3
  • 11

2 Answers2

2

Are you using the MacPorts python2.7? Try launching Python this way:

/opt/local/bin/python2.7
Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • Yes, that worked! Am I able to remove all the other python versions and launch this python by "python" alone? – Alvin Aug 17 '11 at 17:31
  • 1
    Don't try to remove the Apple-supplied system Pythons, they are part of OS X. The easiest thing to do is, first, modify your shell profile to ensure MacPorts-installed ports are found (see https://trac.macports.org/wiki/InstallingMacPorts#a3.Settheshellenvironment) and then use `sudo port select python python27` to select the default python path associated with the MacPorts `python` command. – Ned Deily Aug 17 '11 at 17:38
0

I'm not 100% sure if this solves your problem, but gdal is in the osgeo namespace. So you should try importing gdal like this:

from osgeo import gdal

The gdal namespace itself is deprecated.

Constantinius
  • 34,183
  • 8
  • 77
  • 85