[gdal-dev] Problem importing osgeo module in Python

Mateusz Loskot mateusz at loskot.net
Fri Aug 8 12:50:49 EDT 2008


Roger André wrote:
> Hi everyone,
> 
> I'm getting a new machine setup and have hit a snag with the GDAL
> installation.  I've installed GDAL from source onto a CentOS box using the
> gdal-1.5.2.tar.gz file, and with the following parameters:
> 
> $ sudo ./configure --prefix=/export --with-pg=/export/bin/pg_config
> --with-python
> $ make
> $ make install
> $ which gdalinfo
>     /export/bin/gdalinfo
> --> Good!
> 
> The problem comes when I try to import the osgeo module in Python.
> 
> $ python
> Python 2.3.4 (#1, Dec 11 2007, 05:28:55)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> from osgeo import gdal
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named osgeo
> --> Not good.
> 
> Looking back through the make output, I see that the osgeo modules are being
> created and copied:
>     copying build/lib.linux-x86_64-2.3/osgeo/gdal.py ->
> /export/lib64/python2.3/site-packages/osgeo
> 
> So I tried appending the location to the sys.path in Python to make the
> modules available, but am only partially succesful with that:
> [root at randre-linux ~]# python
> Python 2.3.4 (#1, Dec 11 2007, 05:28:55)
> [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.path.append('/export/lib64/python2.3/site-packages/')
>>>> import osgeo
> --> Good!
> 
>>>> from osgeo import gdal
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "/export/lib64/python2.3/site-packages/osgeo/gdal.py", line 7, in ?
>     import _gdal
> ImportError: libgdal.so.1: cannot open shared object file: No such file or
> directory
> --> Not good.
> 
> So I'm guessing that my gdal libs aren't accessible for some reason, but I'm
> just guessing.  Is there a way that I can fix this at the ./configure stage?

It looks like path where gdal library was installed is not available to 
loader.

Try this:

export LD_LIBRARY_PATH=/path/to/dir/with/libgdal.so


Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org


More information about the gdal-dev mailing list