又遇到了gdal的常见错误:
Traceback (most recent call last):
......
File "/usr/local/lib/python3.6/site-packages/osgeo/gdal.py", line 2759, in ReadAsArray
from osgeo import gdalnumeric
File "/usr/local/lib/python3.6/site-packages/osgeo/gdalnumeric.py", line 2, in <module>
from osgeo.gdal_array import *
File "/usr/local/lib/python3.6/site-packages/osgeo/gdal_array.py", line 28, in <module>
_gdal_array = swig_import_helper()
File "/usr/local/lib/python3.6/site-packages/osgeo/gdal_array.py", line 20, in swig_import_helper
import _gdal_array
ModuleNotFoundError: No module named '_gdal_array'
原因
系统centos7,gdal版本2.4.4从代码编译,python语言绑定是自己编译的。要注意的是,确保swig/python中make的时候系统中已安装numpy。
解决方法
- 先把osgeo包卸载:pip uninstall osgeo 或 conda remove osgeo (有可能出错,自己把已安装文件清理干净)
- 看看numpy没安装的话安装上:pip install numpy
- swig/python 中重新编译安装:make clean && make && sudo make install