numpyversiongdal

ImportError: numpy.core.multiarray failed to import GDAL


This question is already on StackOverflow (ImportError: numpy.core.multiarray failed to import) but no Answer helped.

I did install GDAL: GDAL-3.4.2-cp37-cp37m-win_amd64.whl and numpy: numpy-1.21.6+mkl-cp37-cp37m-win_amd64.whl from the website : https://www.lfd.uci.edu/~gohlke/pythonlibs/#_gdal

By using the command .ReadAsArray(0,0,500,500) I am getting this error:

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

Traceback (most recent call last):

  File "D:\adress\Codes\EdgeN2m.py", line 26, in <module>
    e = EDGE.ReadAsArray(0,0,500,500)

  File "C:\Users\name\miniconda3\lib\site-packages\osgeo\gdal.py", line 3655, in ReadAsArray
    from osgeo import gdal_array

  File "C:\Users\name\miniconda3\lib\site-packages\osgeo\gdal_array.py", line 13, in <module>
    from . import _gdal_array

ImportError: numpy.core.multiarray failed to import


Solution

  • You can install the numpy with different version to check which one can work.

    For me, I install gdal-3.4.3 which is compatible with numpy-1.22.0

    Hope this helps.