gdal错误:ModuleNotFoundError: No module named '_gdal_array'

又遇到了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 
    from osgeo.gdal_array import *
  File "/usr/local/lib/python3.6/site-packages/osgeo/gdal_array.py", line 28, in 
    _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。

解决方法

  1. 先把osgeo包卸载:pip uninstall osgeo 或 conda remove osgeo (有可能出错,自己把已安装文件清理干净)
  2. 看看numpy没安装的话安装上:pip install numpy
  3. swig/python 中重新编译安装:make clean && make && sudo make install

参考
https://stackoverflow.com/questions/45289299/python-3-4-importerror-no-module-named-gdal-arrayno-module-named-gdal-arra

你可能感兴趣的:(gdal错误:ModuleNotFoundError: No module named '_gdal_array')