[GRASS-user] Grass 6.4 & python.
Glynn Clements
glynn at gclements.plus.com
Wed Apr 29 03:57:17 EDT 2009
Milton Cezar Ribeiro wrote:
> I started grass under Msys and with the flag -wx.
> My difficult now I how can I get starting, with a simple example, like
> these on the grass-python page:
> My question is how can I make python find the "grass" to run the import.
> I need to start python inside a MSYS -> GRASS session, like R do?
In order to find grass.py, PYTHONPATH needs to include
$GISBASE/etc/python. This is done automatically when you start GRASS.
However, the functions in grass.py run GRASS commands, and so require
the usual GRASS environment (GISBASE, GISRC, etc). So you need to
either run the Python script from within a GRASS session, or set up
the GRASS environment by some other means.
If you want to write a stand-alone program, you could always have the
Python script set up the GRASS environment, e.g. from registry keys
(or if this is for your own use, just hard-code everything). You can
add directories to the path used for importing Python modules by
modifying sys.path, e.g.:
import sys
...
gisbase = os.normpath(os.environ['GISBASE'])
pydir = os.path.join(gisbase, "etc", "python")
sys.path.append(pydir)
You still need to figure out how to determine the database, location,
and mapset, though.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list