When I run my script outside ArcGIS it works because during execution script uses a GDAL and OGR modules from osgeo. When I use script as a tool in ArcGIS it does not work. In PySripter I can import all modules and it work. In Python Window in ArcGIS I cannot import because I get this error:
Parsing error SyntaxError: invalid syntax (line 2)
import ogr
Runtime error
Traceback (most recent call last):
File “”, line 1, in
File “C:Python27ArcGIS10.1libsite-packagesosgeoogr.py”, line 26, in
_ogr = swig_import_helper()
File “C:Python27ArcGIS10.1libsite-packagesosgeoogr.py”, line 22, in swig_import_helper
_mod = imp.load_module(‘_ogr’, fp, pathname, description)
ImportError: DLL load failed:
In the case when I import gdal in ArcGIS Python Window I do not get this error.
How to force arcgis to import ogr and use it in ModelBuilder or Script??
I check a lot of solutions includin reinstallation, changing and adding environment variables. I checked :
- http://pythongisandstuff.wordpress.com/2011/07/07/installing-gdal-and-ogr-for-python-on-windows/
- http://www.wildsong.biz/index.php/Running_GDAL_scripts_in_ESRI_Model_Builder
and I still do not have a good solution. Any idea?
UPDATE:
I also try use direct importing in my script:
import imp
ogr = imp.load_source(‘ogr’, ‘c:Python27Libsite-packagesosgeoogr.py’
and I get the same error. If I use this method in standalone script it works.