10

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 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 "<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()

I ́m using ArcGIS 10 and GRASS 6.4.2 on a Windows 7 64 Bit machine.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 14, 2013 at 10:53

1 Answer 1

6

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
sys.path.append('\path\to\grass\bindings.py')

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

Chad Cooper
12.8k4 gold badges48 silver badges87 bronze badges
answered Jan 14, 2013 at 13:54
7
  • 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? Commented Jan 14, 2013 at 14:25
  • 1
    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? Commented Jan 14, 2013 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. :-( Commented Jan 14, 2013 at 15:08
  • 1
    Hmmm....one more idea for you to try: It looks like you can install GRASS without using the bundled python, as per the linked post. Perhaps try a reinstall and force GRASS to use the Arc python install? lists.osgeo.org/pipermail/grass-user/2012-June/065178.html Commented Jan 15, 2013 at 14:28
  • 1
    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 Commented Jan 29, 2013 at 19:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.