I have a Mac and am very new to this coding stuff..

I'm using a code that includes

import osgeo as gdal

and so I've downloaded GDAL from https://pypi.python.org/pypi/GDAL/ which has a folder called "osgeo" and a python script called "gdal", but when I run the whole code I get the message "ImportError: No module named 'osgeo'"

Can someone give me the babysteps about how to import this correctly?


Your code is wrong. Do this:

from osgeo import gdal

GDAL is a module of the osgeo package. You don't ever import osgeo itself. In Python a package is a convenient collection of modules and provides a 'name-space' for that collection. So, you can drill down further and import specific functions or variables from a module within a package like this:

from aPackage import aModule.someFunction

The statement from osgeo import gdal fetches everything in the gdal module. Sometimes you only want parts of a module and it can be more efficient to just import what you need. Don't worry about that for now. In your case, the three most common imports you will do when using GDAl are

from osgeo import gdal
from osgeo import ogr
from osgeo import osr

GDAL gives you raster functionality. OGR gives you vector functionality and OSR gives you spatial reference functionality. Have a look at this excellent if old tutorial. It will help you get started.

  • Thanks for the quick response, but I'm still getting the same error message: Traceback (most recent call last): File "/Users/Mike/phenology.py", line 9, in <module> from osgeo import gdal ImportError: No module named 'osgeo'
    – Mike T
    Oct 23 '14 at 16:18

You cannot only unzip the folder, you must install the module with python setup.py installbut osgeo is a Python wrapper of the GDAL C++ library. Therefore you need to install first the GDAL library and then install the Python module witch uses the GDAL libraries

Dependencies: * libgdal (1.11.0 or greater) and header files (gdal-devel)

You can compile and install yourself the GDAL C++ library and after the Python module but for Mac OS X there are many complete solutions (GDAL + osgeo installation):

  • I've tried downloading it using both methods but each time it asks me for a password? I tried inputting the password for my computer but that doesn't seem to work
    – Mike T
    Oct 23 '14 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.