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 file that I put as the toolbox script:

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

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
for %%f in (%OSGEO4W_ROOT%\etc\ini\*.bat) do call %%f
@echo on

@C:\OSGeo4W\bin\python.exe %1 tries to import gdal:

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

When I run 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
) 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 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.