[GRASS-user] Using Python scripts that call GRASS modules or access GRASS layers from outside the GRASS.app with Mac OS X: a little summary

Glynn Clements glynn at gclements.plus.com
Sun Jul 8 15:42:45 PDT 2012


Martin Laloux wrote:

> *1) if you want to use the GRASS modules from outside in the shell
> (terminal) without opening the GRASS application
> *
> GRASS_and_Python <http://grass.osgeo.org/wiki/GRASS_and_Python> gives
> examples to set the environment variables to call the GRASS modules from
> outside for Windows and Linux, but nothing for Mac OS X. The solution is
> easy if you know the structure of the applications of William Kyngesburye:
> 
> *export GISBASE="/Applications/GRASS-6.4.app/Contents/MacOS"*
> export PATH="$PATH:$GISBASE/bin:$GISBASE/script:$GISBASE/lib"

$GISBASE/lib should only be added to PATH on Windows, where $PATH is
used for locating DLLs. The equivalent variable is LD_LIBRARY_PATH on
Linux and DYLD_LIBRARY_PATH on MacOSX.

> export PYTHONPATH="${PYTHONPATH}:$GISBASE/etc/python/"
> export PYTHONPATH="${PYTHONPATH}:$GISBASE/etc/python/grass"
> export PYTHONPATH="${PYTHONPATH}:$GISBASE/etc/python/grass/script"

The last two lines shouldn't be there. The main Python scripting
module should be imported as "grass.script", while optional modules
should use "grass.script.array" etc.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list