martinscheiber

Is there a way to use ArcPy and PyGRASS tools in the same Python script?

Discussion created by martinscheiber on Jan 14, 2013
Latest reply on Jan 15, 2013 by curtvprice
I´m trying to write a Python script, that includes different ArcPy / ArcGIS commands and want to combine it with GRASS geoprocessing tools.

Unfortunately importing the GRASS libraries doesn´t work.
import grass.script as grass

ends in an error:
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ImportError: No module named script


I know that GRASS GIS installs it's own Python version. Isn´t there a way to combine the ArcGIS and the GRASS GIS installation of Python? I tried copying the pygrass module (or what I thought it might be) to the "C:\Python26\ArcGIS10.0\Lib\site-packages\" folder. I´m getting a different error message, but it´s still not working.

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python26\ArcGIS10.0\lib\site-packages\grass\script\__init__.py", line 1, in <module>
    from core   import *
  File "C:\Python26\ArcGIS10.0\lib\site-packages\grass\script\core.py", line 38, in <module>
    gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'))
  File "C:\Python26\ArcGIS10.0\lib\ntpath.py", line 96, in join
    assert len(path) > 0
TypeError: object of type 'NoneType' has no len()


In a second step I tried to connect to the .py files from GRASS GIS, but it´s still not working.

import sys
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/core.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/db.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/vector.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/raster.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/setup.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/array.py')
sys.path.append('C:/Program Files (x86)/GRASS GIS 6.4.3RC2/etc/python/grass/script/task.py')

import grass.script as grass 


I´m using ArcGIS 10 and GRASS 6.4.3 on a Windows 7 64 Bit machine. Any help would be highly appreciated.

Outcomes