Running GDAL scripts in ESRI Model Builder: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
mNo edit summary
Line 17: Line 17:


Installation instructions, the compact edition:
Installation instructions, the compact edition:
# Install OSGeo4W (which includes Python 2.7.4)
* Install OSGeo4W (which includes Python 2.7.4) Get it from http://osgeo4w.osgeo.org/
# Update environment to include these variables
* Update environment to include these variables
  GDAL_DATA        C:\OSGed4W\share\gdal
  GDAL_DATA        C:\OSGed4W\share\gdal
  GDAL_DRIVER_PATH  C:\OSGed4W\bin\gdalplugins
  GDAL_DRIVER_PATH  C:\OSGed4W\bin\gdalplugins
  PYTHONHOME        C:\OSGeo4W\apps\Python27
  PYTHONHOME        C:\OSGeo4W\apps\Python27
  PATH              C:\OSGeo4W\bin;%PATH%;C:\OSGeo4W\apps\Python27\Scripts
  PATH              C:\OSGeo4W\bin;%PATH%;C:\OSGeo4W\apps\Python27\Scripts
# Download and install distribute_setup.py http://python-distribute.org/distribute_setup.py
* Download and install distribute_setup.py '''wget http://python-distribute.org/distribute_setup.py'''
# Run it. It will install itself. python distribute_setup.py
* Run it. It will install itself. '''python distribute_setup.py'''
# Download pip. https://raw.github.com/pypa/pip/master/contrib/get-pip.py
* Download pip. '''wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py'''
# Install pip. python get-pip.py
* Install pip. '''python get-pip.py'''
* Install virtualenv. '''pip install virtualenv'''

Revision as of 17:28, 14 June 2013

I have a script that runs fine standalone but I need it to run in ESRI Model Builder. I am doing this for a client. I avoid Model Builder because scripts are maintainable and reliable.

I am using the versions of Python, GDAL, and Shapely.

The script won't run in Model Builder because it sets up its environment for the ESRI version of Python 2.6. This is the symptom

TypeError: cannot create weak reference to 'classobj' object

I believe this means the python interpreter is getting confused and trying to import from the wrong site packages. I think I can use virtualenv to get around this problem.

I found these instructions and I am following them right now. http://www.tylerbutler.com/2012/05/how-to-install-python-pip-and-virtualenv-on-windows-with-powershell/

I had already installed OSGeo4W yesterday, and modified the environment on my desktop Windows 7 (virtual machine) to load it so that I can run python from command line shells. The link above gives help on how to do that so I won't cover it here.

Installation instructions, the compact edition:

  • Install OSGeo4W (which includes Python 2.7.4) Get it from http://osgeo4w.osgeo.org/
  • Update environment to include these variables
GDAL_DATA         C:\OSGed4W\share\gdal
GDAL_DRIVER_PATH  C:\OSGed4W\bin\gdalplugins
PYTHONHOME        C:\OSGeo4W\apps\Python27
PATH              C:\OSGeo4W\bin;%PATH%;C:\OSGeo4W\apps\Python27\Scripts