ImportError:无法从“osgeo”导入名称“_gdal_array”

问题描述 投票:0回答:1

我创建一个新环境,安装 numpy,然后安装 GDAL。 GDAL导入成功,我可以使用

gdal.Open(
打开图像,但我在尝试使用
ImportError: cannot import name '_gdal_array' from 'osgeo'
时出现
ReadAsRaster
错误。

pip list
回报:

GDAL       3.6.2
numpy      1.24.2
pip        23.0
setuptools 65.6.3
wheel      0.38.4

完全难住了,有人遇到过这个吗? Google 告诉我首先安装 numpy 是解决方案(但这没有帮助)。帮助将不胜感激。

python gdal
1个回答
0
投票

Pip 很可能一遍又一遍地缓存和重新安装错误版本的 GDAL,即使您安装了 numpy。这是为我修复的内容:

pip3 install --no-cache-dir --force-reinstall 'GDAL[numpy]==3.6.2'

没有

--no-cache-dir
的安装会导致pip重用编译的轮子:

% pip3 install --force-reinstall "GDAL[numpy]==3.6.2" 
Collecting GDAL[numpy]==3.6.2
  Using cached GDAL-3.6.2-cp311-cp311-macosx_13_0_x86_64.whl
Collecting numpy>1.0.0
  Using cached numpy-1.24.2-cp311-cp311-macosx_10_9_x86_64.whl (19.8 MB)
Installing collected packages: numpy, GDAL
  Attempting uninstall: numpy
    Found existing installation: numpy 1.24.2
    Uninstalling numpy-1.24.2:
      Successfully uninstalled numpy-1.24.2
  Attempting uninstall: GDAL
    Found existing installation: GDAL 3.6.2
    Uninstalling GDAL-3.6.2:
      Successfully uninstalled GDAL-3.6.2
Successfully installed GDAL-3.6.2 numpy-1.24.2
© www.soinside.com 2019 - 2024. All rights reserved.