richsharp

Problems loading GDAL with arctoolbox

Discussion created by richsharp on Aug 18, 2011
I'm attempting to launch Python 2.5 from a script in an ArcToolbox. I'm trying to get around the problem of using GDAL in ArcGIS10.

The main.py file that I put as the toolbox script:

import subprocess
p = subprocess.Popen(['C:\OSGeo4W\gdal_python_exec.bat', 'X:\\local\\import_tests.py'])


gdal_python_exec.bat is a windows batch script that fires up the 2.5 version of Python I want while also setting up some environment variables:
@echo off
set OSGEO4W_ROOT=C:\OSGeo4W
PATH=%OSGEO4W_ROOT%\bin;%PATH%
for %%f in (%OSGEO4W_ROOT%\etc\ini\*.bat) do call %%f
@echo on

@C:\OSGeo4W\bin\python.exe %1


import_tests.py tries to import gdal:

try:
    from osgeo import gdal
    raw_input('Imported! (Press enter)')
except Exception, e:
    print(e)
    raw_input('Failed! (Press enter)')


When I run main.py at a DOS command line using ArcGIS10's version of Python (like this
X:\local\workspace\invest-natcap.invest-3>C:\Python26\ArcGIS10.0\python.exe gdal
_arc_test.py
) things work fine. However, if I take the same script and add it to a 'toolbox' I get a "DLL not found" for the GDAL lib inside the import_tests.py file!

How can this happen when subprocess is the module that's launching a different Python interpreter? Any ideas on what could be happening?

P.S. I can verify that the os.environ['PATH'] variables are the same in both calls.

Outcomes