Search code examples
gdal

ModuleNotFoundError: No module named '_gdal'


When trying from osgeo import gdal I got the error ModuleNotFoundError: No module named '_gdal'. I installed gdal 3.5.1 from binary.


Solution

  • Try gdalinfo --version if you have an error like this : gdalinfo: error while loading shared libraries: libgdal.so.31: cannot open shared object file: No such file or directory do this:

    1. Find the location of libgdal.so.31 with the command find / -name libgdal.so*. for me the result was : /usr/local/lib64/libgdal.so.31
    2. The folder where is located libgdal.so.31 should be part of $LD_LIBRARY_PATH. If it is not: add it with LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path_to_your_library for my case it is export LD_LIBRARY_PATH=/usr/local/lib64:$LD_LIBRARY_PATH
    3. Try again gdalinfo --version, if it works try again to import gdal : from osgeo import gdal => Celebrate. If gdalinfo --version still work, repeat the process for error message specified libraries => celebrate