Search code examples
pythonlinuxgdal

Installing GDAL python binding Linux


I've been trying to install the python GDAL binding from source with ./configure --with-python but when i attemp

from osgeo import gdal

I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
 File "osgeo/__init__.py", line 21, in <module>
   _gdal = swig_import_helper()
  File "osgeo/__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: libgdal.so.1: cannot open shared object file: No such file or directory

It seems to me to be an error with swig.


Solution

  • If you have GDAL installed and libgdal.so exists, it looks like the python module is just not finding the library. You can try setting the LD_LIBRARY_PATH environment variable to point to the directory containing libgdal.so (e.g. /usr/local/lib). If that works, run ldconfig to update your library settings so you won't have to set LD_LIBRARY_PATH every time (which many consider a bad idea).