Take the 2-minute tour ×

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):
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 it) 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 "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

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

share|improve this question

1 Answer 1

Most likely the grass version of Python has installed its own Python bindings into a grass specific site-packages. One non-ideal option would be to add the following prior to importing grass.script:

import sys

What this is doing is temporarily adding grass to your $PYTHONPATH so that your ArcGIS10.0 Python installation finds it when searching for imports.

share|improve this answer
Hey Jay, thanks for your tip. I think the respective folder is .../etc/python/grass/script/. Do I have to reference a specific .py file or all of them? –  Martin Jan 14 '13 at 14:25
Yes, for example, if I wanted to add the gdal bindings from another folder I would need to use python_install/site-packages/osgeo/gdal.py. Does a grass.py script exist in the grass directory? –  Jay Laura Jan 14 '13 at 14:39
There are several .py files, unfortunately none with a clear name like grass.py . I have tried to reference all of them. Unfortunately it still doesn´t work. :-( –  Martin Jan 14 '13 at 15:08
Do you get a meaningful stack trace or is it just an import error? –  Jay Laura Jan 14 '13 at 15:47
I you asked about pygrass but maybe this post is on interest anyway. It talks about arcpy bindings for gdal. arcgis.com/home/item.html?id=1eec30bf5fa042a5a2227b094db89441 –  dango Jan 29 '13 at 19:37

Your Answer


