I'm attempting to launch a version Python 2.5 that supports GDAL from an ArcGIS10 toolbox script. I'm doing this because I'm having loads of trouble importing the GDAL library directly into Arc, and I'm writing an application that will need to be backwards compatiable with Arc 9.3.

When I run main.py at a DOS command line as C:\Python26\ArcGIS10.0\python.exe gdal_arc_test.py things work fine. However, if I take the same script and add it as a 'toolbox' inside of Arc launch it from there, 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? It feels like the version of Python launched from Arc's tool box does something very strange, but I would have thought the subprocess call would separate that stuff out.

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

Try comparing the contents of your sys.path in your import_tests.py script between when you run it from a command prompt and from ArcToolbox. You may need to append the path containing the osgeo module to sys.path.
–
blah238Aug 19 '11 at 5:33

Unfortunately sys.path is identical between the two calls except for an extra directory. If I manually remove that directory I still get the same error. Any other ideas?
–
RichAug 19 '11 at 21:08

This ArcGIS forum post suggests modifying os.environ after importing arcpy but before importing gdal. Not sure whether this also applies with arcgisscripting.
–
blah238Aug 19 '11 at 21:57

Thanks for checking; I read that post as well. Unfortunately updating the os.environ['PATH'] before loading gdal didn't work either.
–
RichAug 19 '11 at 22:05

1 Answer
1

if the py2.5 script is relatively stable, meaning you don't need to change it much or often, try turning it into a self contained executable and call that instead. There are two python-to-exe programs I see mentioned often: py2exe and pyinstaller. I've personally had the best luck with pyinstaller, though I never used it in a gis-inside-gis fashion such as you are attempting. There are some other py-to-exe's discussed here on Stack Overflow.

However responding to the problem which is driving you to use 2.5: I used python 2.6 with Arcgis 9.3 for a long time to good effect using the recipe at Can I use python 2.6 with ArcGIS 9.3?.