I and my colleagues are running into a very frustrating Python import error while using the OSGeo4W Shell. Any time we attempt to use gdal_calc in a Python script, we get the following error message:
Traceback (most recent call last): File "C:\OSGEO4~1\apps\Python27\Scripts\gdal_calc.py", line 51, in <module> import numpy File "C:\OSGEO4~1\apps\Python27\lib\site-packages\numpy\__init__.py", line 142, in <module> from . import add_newdocs File "C:\OSGEO4~1\apps\Python27\lib\site-packages\numpy\add_newdocs.py", line 13, in <module> from numpy.lib import add_newdoc File "C:\OSGEO4~1\apps\Python27\lib\site-packages\numpy\lib\__init__.py", line 8, in <module> from .type_check import * File "C:\OSGEO4~1\apps\Python27\lib\site-packages\numpy\lib\type_check.py", line 11, in <module> import numpy.core.numeric as _nx File "C:\OSGEO4~1\apps\Python27\lib\site-packages\numpy\core\__init__.py", line 26, in <module> raise ImportError(msg) ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try `git clean -xdf` (removes all files not under version control). Otherwise reinstall numpy. Original error was: DLL load failed: %1 is not a valid Win32 application.
The script we're using works fine in Cygwin on multiple machines, so we know that it's not the script itself, but rather something to do with our OSGEO installations. I have installed and uninstalled numpy in my OSGEO4W64 Python2.7 installation numerous times, both using
pip install --update
and using Gohlke's pre-compiled Numpy+MKL binary wheel. My numpy and scipy package installations have all been the correct bit type for my Python installation (64 bit). Oddly enough, I can import numpy without issue when I call it directly in the OSGeo4W shell.
While I've seen numerous potential solutions for this error online, they almost universally apply to Anaconda installations, and I have no idea how to apply them to OSGEO4W.
A few things about my system: I'm running Win10 64bit, with the Python2.7 installation that came with OSGEO. My OSGEO and QGIS installs are up to date. For reasons beyond my control, I cannot switch to using Python 3.x, and I do not have Administrative access to my computer without a call to the company Helpdesk, so I generally cannot set my own Python environment paths. There is also another installation of Python2.7 on my computer courtesy of ArcGIS.