I hope someone can help me with this issue with gdal_calc.py. When I call gdal_calc.py from the command line, I get the following error (after displaying the error message I will describe my current environment):
C:\Users\xx> gdal_calc.py
RuntimeError: module compiled against API version 9 but this version of numpy is
7
Traceback (most recent call last):
File "C:\Anaconda2\Scripts\gdal_calc.py", line 46, in <module>
from osgeo import gdalnumeric
File "C:\Python27\ArcGIS10.3\lib\site-packages\osgeo\gdalnumeric.py", line 1,
in <module>
from gdal_array import *
File "C:\Python27\ArcGIS10.3\lib\site-packages\osgeo\gdal_array.py", line 26,
in <module>
_gdal_array = swig_import_helper()
File "C:\Python27\ArcGIS10.3\lib\site-packages\osgeo\gdal_array.py", line 22,
in swig_import_helper
_mod = imp.load_module('_gdal_array', fp, pathname, description)
ImportError: numpy.core.multiarray failed to import
I am running Windows 7, installed Anaconda and the command line calls Anaconda's python version, and I have installed ArcGIS (my employer requires to script in ArcGIS from time to time).
When I call gdal from the command line, it runs without problems. Also, whenever I run gdal_polygonize.py there is no issue. So far, I have only run into problems when running gdal_calc.py as it seems to access the osgeo installation in ArcGIS and not the osgeo installation in Anaconda.
The osgeo path in Anancondo is: C:\Anaconda2\Lib\site-packages\osgeo
The osgeo path in ArcGIS is: C:\Python27\ArcGIS10.3\Lib\site-packages\osgeo
Also, to confirm the Python installation accessed:
Python 2.7.11 |Anaconda 4.0.0 (32-bit)| (default, Mar 4 2016, 15:18:41) [MSC v.
1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
-
I guess that you should update numpy stackoverflow.com/questions/20999939/…user30184– user301842016年06月09日 21:56:37 +00:00Commented Jun 9, 2016 at 21:56
-
@user30184 I already updated numpy in Anaconda previously. I did read that thread already, but really don't think this is the issue.user1738753– user17387532016年06月09日 22:07:17 +00:00Commented Jun 9, 2016 at 22:07
2 Answers 2
Your ArcGIS python is the system default. So when you run a python script without specifying which python to use, the ArcGIS one is used.
Don't upgrade the ArcGIS numpy, you can break arcpy.
You can run gdal_calc.py using the Anaconda python using something like path\to\anaconda\python path\to\gdal_calc.py etc...
If you don't want to do this every time you could create a gdal_calc.cmd
file that contains path\to\anaconda\python path\to\gdal_calc.py %*
-
thank you that is it. I will try to fix the registry tomorrow, and see if I can change the path environment so that I do not have to use this work around. gis.stackexchange.com/questions/86850/…user1738753– user17387532016年06月10日 01:31:04 +00:00Commented Jun 10, 2016 at 1:31
-
No don't change the default python, you'll cause issues with ArcGISuser2856– user28562016年06月10日 01:32:39 +00:00Commented Jun 10, 2016 at 1:32
I just had this same problem. Including the full path to gdal_calc.py was only part of the solution for me.
Using Spyder (Anaconda) with Python 2.7, I had to include the statement:
os.system('python path\to\anaconda\python path\to\gdal_calc.py -A filename -B filename --outfile=out.tif --calc=(A+B)')
Also note that if using a numpy function in the --calc statement (i.e., fmax), then the calc statement should be written: --calc="numpy.fmax(A,B)"
Explore related questions
See similar questions with these tags.