I'm trying to import gdal_array in python but I get ModuleNotFoundError: No module named '_gdal_array'.
The strange thing is that this problem does not occur if I use system's python 3.8. It only occurs inside python3.8 virtual environment
Code that works (on terminal):
python3.8
from osgeo import gdal_array
Code I used to test it in venv and doesn't work (on terminal):
virtualenv venv -p $(which python3.8)
source venv/bin/activate
pip install numpy
pip install osgeo
pip install gdal==$(gdal-config --version)
python3.8
from osgeo import gdal_array
Above code results in:
>>> from osgeo import gdal_array
Traceback (most recent call last):
File "/.../venv/lib/python3.8/site-packages/osgeo/gdal_array.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_gdal_array', [dirname(__file__)])
File "/usr/lib/python3.8/imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_gdal_array'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../venv/lib/python3.8/site-packages/osgeo/gdal_array.py", line 28, in <module>
_gdal_array = swig_import_helper()
File "/.../venv/lib/python3.8/site-packages/osgeo/gdal_array.py", line 20, in swig_import_helper
import _gdal_array
ModuleNotFoundError: No module named '_gdal_array'
>>>
(Exact output on terminal shown here)
My question is what might be the problem and how could I fix it?
Other answers suggest to install numpy first, which I do.