I am trying to run some Python code using the Python window in ArcGIS 10.1 that uses both the arcpy
and gdal
modules. However, when I try and import the gdal
module I get an error:
ImportError: No module named osgeo
Obviously it can't find the module, so I have added my main python site-packages directory to the sys.path
list:
sys.path.append(r"C:\Python27\lib\site-packages")
However, when I try and run import osgeo
or from osgeo import gdal
I get the following error:
Runtime error
Traceback (most recent call last):
File "", line 1, in
File "C:\Python27\lib\site-packages\osgeo\__init__.py", line 21, in
_gdal = swig_import_helper()
File "C:\Python27\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.
I've found various resources on the internet that seem to talk about similar problems (for example this question and this forum post, but they seem to be out-of-date (ie. not using ArcGIS 10.1) or not asking quite the same question.
Of course, importing osgeo
from a normal non-Arc Python window works fine, and I have compared sys.path
and os.environ['PATH']
between the scripts and updated them so that they are the same, and it doesn't seem to fix the problem.
Does anyone have any idea how I can get this to work?
Answer
@robintw has confirmed it in the comments.
ImportError: DLL load failed: %1 is not a valid Win32 application.
From the error, it would seem that your Python 2.7 installation is 64-bit. You'll have to install the 32-bit version of Python and GDAL.
No comments:
Post a Comment