Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named _gdal

Tags:

python

gdal

I am trying to run a Python script test.py to test the gdal library. The script contains the line:

from osgeo import gdal

At that line I get the traceback:

File "~/test.py", line 9, in <module>
    from osgeo import gdal
File "/usr/local/lib/python2.7/site-packages/GDAL-2.2.0/osgeo/__init__.py", line 21, in <module>
    gdal = swing_import_helper()
File "/usr/local/lib/python2.7/site-packages/GDAL-2.2.0/osgeo/__init__.py", line 13, in swig_import_helper
    import gdal
ImportError: No module named _gdal

I don't see any _gdal Python files or any scripts that define _gdal. Do I need to install another (prerequisite) library that defines _gdal? The GDAL package should include everything needed to install the library and run scripts that import gdal.

like image 735
PyNerd Avatar asked May 16 '17 15:05

PyNerd


1 Answers

In my case, find the osgeo directory from site-packages or dist-packages in your python lib directory, and then rename _gdal.cpython-35m-x86_64-linux-gnu.so as _gdal.so, other files also like this. Then you can import gdal correctly.

like image 124
user7175903 Avatar answered Sep 18 '22 11:09

user7175903