Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm really getting mad with this. ArcGIS sometimes can be so just...irritating! Forgive me if this question is by any means duplicating this one or similar ones, but I really can't find my way out of this problem.

I have a x64 Windows Server 2012 machine (pretty cutting-edge, isn't it?) and a 32-bit ArcMap 10.1 installation on it, as well as a 64-bit ArcGIS Server installation. I came up with having two different Python 2.7 installations on my machine, both placed by ArcGIS:

C:\Python27\ArcGIS10.1\     #32 bit Python 2.7
C:\Python27\ArcGISx6410.1\  #64 bit Python 2.7

Now, what I want to do is to make an ArcMap tool which peforms calls to GDAL 1.9 Python binding library. My tool starts with a standard import of the gdal bindings:

import gdal
from gdalconst import *
[...]

I therefore installed (using gisinternals.com/sdk msi installers) BOTH 32 AND 64 bit GDAL core binaries and binding libraries, so I have:

#GDAL core binaries
C:\Program Files\GDAL       #64 bit
C:\Program Files (x86)\GDAL #32 bit

#GDAL bindings
C:\Python27\ArcGIS10.1\Lib\site-packages\osgeo     #32 bit
C:\Python27\ArcGISx6410.1\Lib\site-packages\osgeo  #64 bit

#PATH environment variable
echo %PATH%
C:\Program Files (x86)\GDAL;[...]

If I try to import the gdal bindings via both the Python interpreters, I get the followings:

C:\>C:\Python27\ArcGIS10.1\python.exe -m gdal
Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.1\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\ArcGIS10.1\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\ArcGIS10.1\lib\site-packages\gdal.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\Python27\ArcGIS10.1\lib\site-packages\osgeo\__init__.py", line 29, in
 <module>
    _gdal = swig_import_helper()
  File "C:\Python27\ArcGIS10.1\lib\site-packages\osgeo\__init__.py", line 25, in
 swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: %1 is not a valid Win32 application.

C:\>C:\Python27\ArcGISx6410.1\python.exe -m gdal
Traceback (most recent call last):
  File "C:\Python27\ArcGISx6410.1\lib\runpy.py", line 162, in _run_module_as_mai
n
    "__main__", fname, loader, pkg_name)
  File "C:\Python27\ArcGISx6410.1\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python27\ArcGISx6410.1\lib\site-packages\gdal.py", line 2, in <module
>
    from osgeo.gdal import deprecation_warn
  File "C:\Python27\ArcGISx6410.1\lib\site-packages\osgeo\__init__.py", line 21,
 in <module>
    _gdal = swig_import_helper()
  File "C:\Python27\ArcGISx6410.1\lib\site-packages\osgeo\__init__.py", line 17,
 in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: %1 is not a valid Win32 application.

and the very same error is given by the ArcMap Python shell when I try to run the tool:

Traceback (most recent call last):
  File "C:\processors\URBAN_CLASS\URBAN_CLASS.py", line 2, in <module>
    import GLCM_wrapper.GLCM_wrapper
  File "C:\processors\URBAN_CLASS\GLCM_wrapper\GLCM_wrapper.py", line 2, in <module>
    import gdal
  File "C:\Python27\ArcGIS10.1\lib\site-packages\gdal.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\Python27\ArcGIS10.1\lib\site-packages\osgeo\__init__.py", line 29, in <module>
    _gdal = swig_import_helper()
  File "C:\Python27\ArcGIS10.1\lib\site-packages\osgeo\__init__.py", line 25, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: %1 is not a valid Win32 application.

In addition, I tried to have the sys.path printed out from the ArcMap Python shell:

['C:\\processors\\URBAN_CLASS',
u'c:\\program files (x86)\\arcgis\\desktop10.1\\arcpy',
'C:\\Windows\\SYSTEM32\\python27.zip',
'C:\\Python27\\ArcGIS10.1\\Lib',
'C:\\Python27\\ArcGIS10.1\\DLLs',
'C:\\Python27\\ArcGIS10.1\\Lib\\lib-tk',
'C:\\Windows\\system32',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\bin',
'C:\\Python27\\ArcGIS10.1',
'C:\\Python27\\ArcGIS10.1\\lib\\site-packages',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\arcpy',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.1\\ArcToolbox\\Scripts']

Any hint/idea on how to make my tool correctly import the gdal bindings? I'm completely stuck!

share|improve this question

1 Answer 1

I finally managed to make it work...Hope this is useful for others, too.

  1. I re-installed the GDAL 1.9 bindings using the proper installer in this page http://www.gisinternals.com/sdk/PackageList.aspx?file=release-1600-gdal-1-9-mapserver-6-2.zip which lists the GDAL core binaries and bindings components that are compiled daily using the Microsoft Visual Studio 2010 compiling environment
  2. Then, I installed what appears to be an ESRI-made Python binding library for GDAL 1.8 (I am using 1.9, anyway...).

Seems to work.

They say: "have faith" - I will.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.