[GIS] Gdal_calc.py problems from command line

anacondaarcpycommand linegdalwindows

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.

Best Answer

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 %*

Related Question