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.
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
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.
-
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– Martin2013年01月14日 14:25:09 +00:00Commented Jan 14, 2013 at 14:25
-
1Yes, 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 agrass.py
script exist in thegrass
directory?Jay Laura– Jay Laura2013年01月14日 14:39:07 +00:00Commented 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. :-(Martin– Martin2013年01月14日 15:08:30 +00:00Commented Jan 14, 2013 at 15:08
-
1Hmmm....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.htmlJay Laura– Jay Laura2013年01月15日 14:28:02 +00:00Commented Jan 15, 2013 at 14:28
-
1I 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=1eec30bf5fa042a5a2227b094db89441dango– dango2013年01月29日 19:37:56 +00:00Commented Jan 29, 2013 at 19:37
Explore related questions
See similar questions with these tags.