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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With