Opened 7 years ago
Closed 7 years ago
#6936 closed defect (invalid)
can't import gdalnumeric (numpy version mismatch)
Reported by: | saultdon | Owned by: | hobu |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | PythonBindings | Version: | 2.2.0 |
Severity: | normal | Keywords: | numpy gdalnumeric |
Cc: |
Description
I've built gdal against the 2.2 release branch and running 2.2.r39208.
In python I can't import gdalnumeric. It complains about the module conflicting with the numpy version.
>>> from osgeo import gdal >>> import numpy >>> import gdalnumeric RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/gdalnumeric.py", line 5, in <module> from osgeo.gdal_array import * File "/usr/lib/python2.7/site-packages/osgeo/gdal_array.py", line 28, in <module> _gdal_array = swig_import_helper() File "/usr/lib/python2.7/site-packages/osgeo/gdal_array.py", line 24, in swig_import_helper _mod = imp.load_module('_gdal_array', fp, pathname, description) ImportError: numpy.core.multiarray failed to import >>> import osgeo.gdalnumeric RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/osgeo/gdalnumeric.py", line 1, in <module> from osgeo.gdal_array import * File "/usr/lib/python2.7/site-packages/osgeo/gdal_array.py", line 28, in <module> _gdal_array = swig_import_helper() File "/usr/lib/python2.7/site-packages/osgeo/gdal_array.py", line 24, in swig_import_helper _mod = imp.load_module('_gdal_array', fp, pathname, description) ImportError: numpy.core.multiarray failed to import >>> import numpy.core.multiarray >>>
This is on Linux and I have the following installed:
python2-numpy 1.13.0 python2-scipy 0.19.0 python2-pillow 4.1.1 gdal 2.2.r39205
I tried to recompile the packages above in the same order they're listed, but still can't get the GDAL python module to import gdalnumeric (this is needed for a QGIS plugin).
Change History (4)
comment:1 by , 7 years ago
comment:3 by , 7 years ago
That works fine for me on Ubuntu 16.04 with a manually built numpy 1.13
Here's my procedure.
Build and install numpy 1.13
unzip numpy-1.13.0.zip cd numpy-1.13.0 ./setup.py build PYTHONPATH=$HOME/install-numpy-1.13.0/lib/python ./setup.py install --home=$HOME/install-numpy-1.13.0
Build GDAL python bindings against numpy 1.13:
cd gdal/swig/python PYTHONPATH=$HOME/install-numpy-1.13.0/lib/python make clean PYTHONPATH=$HOME/install-numpy-1.13.0/lib/python make cd ../..
Test :
PYTHONPATH=$HOME/install-numpy-1.13.0/lib/python:$HOME/gdal/swig/python/build/lib.linux-x86_64-2.7 python >>> from osgeo import gdal >>> import numpy >>> numpy.__version__ '1.13.0' >>> import gdalnumeric
Are you sure you don't have several numpy versions installed in your system, and you built against a recent one but run against an older one ?
comment:4 by , 7 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Ah, that's it.
Looks like numpy is installed system wide in /usr/lib/python2.7 (1.13.0) and also at $HOME/.local/lib/python2.7 (1.10.4)!
It was placed in .local while grabbing a module with pip2 install --user landsat-util
which grabbed numpy as a dependency.
Looks like when I drop to python2 terminal it looks for modules in $HOME/.local/lib/python2.7 first instead of the system ones in /usr/lib/python2.7
Not sure how to fix it, will have to do some research for a remedy here. Would be nice to tell pip2 that when it installs a module or package to $HOME/.local/lib/python2.7 to only install dependencies there if they aren't already found in /usr/lib/python2.7
Which distribution is this ?