<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FSonja</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FSonja"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FSonja"/>
	<updated>2026-05-26T05:46:28Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=10479</id>
		<title>GRASS and Python</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=10479"/>
		<updated>2010-03-05T16:49:09Z</updated>

		<summary type="html">&lt;p&gt;⚠️Sonja: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''(for discussions on the new GRASS GUI, see [[GRASS GUI|here]])''&lt;br /&gt;
&lt;br /&gt;
==Python SIGs==&lt;br /&gt;
Python Special Interest Groups are focused collaborative efforts to develop, improve, or maintain specific Python resources. Each SIG has a charter, a coordinator, a mailing list, and a directory on the Python website. SIG membership is informal, defined by subscription to the SIG's mailing list. Anyone can join a SIG, and participate in the development discussions via the SIG's mailing list. Below is the list of currently active Python SIGs, with links to their resources. &lt;br /&gt;
&lt;br /&gt;
See more at http://www.python.org/community/sigs/&lt;br /&gt;
&lt;br /&gt;
==Writing Python scripts in GRASS==&lt;br /&gt;
&lt;br /&gt;
Python is a programming language which is more powerful than shell scripting but easier and more forgiving than C.&lt;br /&gt;
The Python script can contain simple module description definitions which will be processed with {{cmd|g.parser}}, as shown in the example below. In this way with no extra coding a GUI can be built, inputs checked, and a skeleton help page can be generated automatically. In addition it adds links to the GRASS message translation system.&lt;br /&gt;
For code which needs access to the power of C, you can access the GRASS C library functions via the SWIG interface.&lt;br /&gt;
&lt;br /&gt;
* GRASS Python interface to library functions: http://download.osgeo.org/grass/grass6_progman/swig/&lt;br /&gt;
* GRASS Python scripting library: http://download.osgeo.org/grass/grass6_progman/pythonlib.html&lt;br /&gt;
&lt;br /&gt;
Code style: Have a look at [http://trac.osgeo.org/grass/browser/grass/trunk/SUBMITTING_PYTHON SUBMITTING_PYTHON].&lt;br /&gt;
&lt;br /&gt;
=== Creating Python scripts that run in GRASS under MS-Windows ===&lt;br /&gt;
&lt;br /&gt;
The environment variables have to be set as follows:&lt;br /&gt;
 GISBASE= C:\GRASS-64&lt;br /&gt;
 GISRC= C:\Documents and Settings\user\.grassrc6&lt;br /&gt;
 LD_LIBRARY_PATH= C:\GRASS-64\lib&lt;br /&gt;
 PATH= C:\GRASS-64\etc;C:\GRASS-64\etc\python;C:\GRASS-64\lib;C:\GRASS-64\bin;C:\GRASS-64\extralib;C:\GRASS-64\msys\bin;C:\Python26;&lt;br /&gt;
 PYTHONLIB= C:\Python26&lt;br /&gt;
 PYTHONPATH= C:\GRASS-64\etc\python&lt;br /&gt;
 GRASS_SH= C:\GRASS-64\msys\bin\sh.exe&lt;br /&gt;
&lt;br /&gt;
Some hints:&lt;br /&gt;
&lt;br /&gt;
# The Python interpreter (python.exe) needs to be in the PATH&lt;br /&gt;
# Python needs to be associated with the .py extension&lt;br /&gt;
# PATHEXT needs to include .py if you want to be able to omit the extension&lt;br /&gt;
# PYTHONPATH needs to be set to %WINGISBASE%\etc\python&lt;br /&gt;
&lt;br /&gt;
1-3 should be taken care of by the Python installer. 4 needs to be done by the startup (currently, this doesn't appear to be the case on MS-Windows).&lt;br /&gt;
&lt;br /&gt;
=== Running external commands from Python ===&lt;br /&gt;
For information on running external commands from Python, see:&lt;br /&gt;
http://docs.python.org/lib/module-subprocess.html&lt;br /&gt;
&lt;br /&gt;
Avoid using the older os.* functions. Section 17.1.3 lists equivalents&lt;br /&gt;
using the Popen() interface, which is more robust (particularly on&lt;br /&gt;
Windows).&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
==== Display example ====&lt;br /&gt;
Example of Python script, which is processed by g.parser:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
#&lt;br /&gt;
############################################################################&lt;br /&gt;
#&lt;br /&gt;
# MODULE:      d.shadedmap&lt;br /&gt;
# AUTHOR(S):   Unknown; updated to GRASS 5.7 by Michael Barton&lt;br /&gt;
#              Converted to Python by Glynn Clements&lt;br /&gt;
# PURPOSE:     Uses d.his to drape a color raster over a shaded relief map&lt;br /&gt;
# COPYRIGHT:   (C) 2004,2008,2009 by the GRASS Development Team&lt;br /&gt;
#&lt;br /&gt;
#              This program is free software under the GNU General Public&lt;br /&gt;
#              License (&amp;gt;=v2). Read the file COPYING that comes with GRASS&lt;br /&gt;
#              for details.&lt;br /&gt;
#&lt;br /&gt;
#############################################################################&lt;br /&gt;
&lt;br /&gt;
#%Module&lt;br /&gt;
#% description: Drapes a color raster over a shaded relief map using d.his&lt;br /&gt;
#%End&lt;br /&gt;
#%option&lt;br /&gt;
#% key: reliefmap&lt;br /&gt;
#% type: string&lt;br /&gt;
#% gisprompt: old,cell,raster&lt;br /&gt;
#% description: Name of shaded relief or aspect map&lt;br /&gt;
#% required : yes&lt;br /&gt;
#%end&lt;br /&gt;
#%option&lt;br /&gt;
#% key: drapemap&lt;br /&gt;
#% type: string&lt;br /&gt;
#% gisprompt: old,cell,raster&lt;br /&gt;
#% description: Name of raster to drape over relief map&lt;br /&gt;
#% required : yes&lt;br /&gt;
#%end&lt;br /&gt;
#%option&lt;br /&gt;
#% key: brighten&lt;br /&gt;
#% type: integer&lt;br /&gt;
#% description: Percent to brighten&lt;br /&gt;
#% options: -99-99&lt;br /&gt;
#% answer: 0&lt;br /&gt;
#%end&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
from grass.script import core as grass&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    drape_map = options['drapemap']&lt;br /&gt;
    relief_map = options['reliefmap']&lt;br /&gt;
    brighten = options['brighten']&lt;br /&gt;
    ret = grass.run_command(&amp;quot;d.his&amp;quot;, h_map = drape_map,  i_map = relief_map, brighten = brighten)&lt;br /&gt;
    sys.exit(ret)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    options, flags = grass.parser()&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Example for embedding r.mapcalc (map algebra) ====&lt;br /&gt;
&lt;br /&gt;
grass.mapcalc() accepts a template string followed by keyword&lt;br /&gt;
arguments for the substitutions, e.g. (code snippets):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
grass.mapcalc(&amp;quot;${out} = ${rast1} + ${rast2}&amp;quot;,&lt;br /&gt;
              out = options['output'],&lt;br /&gt;
              rast1 = options['raster1'],&lt;br /&gt;
              rast2 = options['raster2'])&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Best practice'': first copy all of the options[] into separate variables at the beginning of main(), i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def main():&lt;br /&gt;
    output = options['output']&lt;br /&gt;
    raster1 = options['raster1']&lt;br /&gt;
    raster2 = options['raster2']&lt;br /&gt;
 &lt;br /&gt;
    ...&lt;br /&gt;
 &lt;br /&gt;
    grass.mapcalc(&amp;quot;${out} = ${rast1} + ${rast2}&amp;quot;,&lt;br /&gt;
                  out = output,&lt;br /&gt;
                  rast1 = raster1,&lt;br /&gt;
                  rast2 = raster2)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Python extensions for GRASS GIS==&lt;br /&gt;
=== wxPython GUI development for GRASS ===&lt;br /&gt;
&lt;br /&gt;
* See the [[GRASS GUI]] wiki page&lt;br /&gt;
&lt;br /&gt;
=== GRASS Python library ===&lt;br /&gt;
&lt;br /&gt;
See [http://download.osgeo.org/grass/grass6_progman/pythonlib.html GRASS Python library]&lt;br /&gt;
&lt;br /&gt;
==== Interfacing with NumPy ====&lt;br /&gt;
&lt;br /&gt;
''Glynn writes:''&lt;br /&gt;
&lt;br /&gt;
The grass.script.array module defines a class &amp;quot;array&amp;quot; which is a&lt;br /&gt;
subclass of numpy.memmap with .read() and .write() methods to&lt;br /&gt;
read/write the underlying file via r.out.bin/r.in.bin.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    import grass.script.array as garray&lt;br /&gt;
    a = garray.array()&lt;br /&gt;
    a.read(&amp;quot;elevation.dem&amp;quot;)&lt;br /&gt;
    b = garray.array()&lt;br /&gt;
    b[...] = (a / 50).astype(int) * 50    # or whatever&lt;br /&gt;
    b.write(&amp;quot;elev.50m&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the array is taken from the current region.&lt;br /&gt;
&lt;br /&gt;
The main drawback of using numpy is that you're limited by available&lt;br /&gt;
memory. Using a subclass of numpy.memmap lets you use files which may&lt;br /&gt;
be much larger, but processing the entire array in one go is likely to&lt;br /&gt;
produce in-memory results of a similar size.&lt;br /&gt;
&lt;br /&gt;
One may also use the scipy matlab interface:&lt;br /&gt;
    &lt;br /&gt;
    ### SH: in GRASS ###&lt;br /&gt;
    r.out.mat input=elevation output=elev.mat&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    ### PY ###&lt;br /&gt;
    import scipy.io as sio&lt;br /&gt;
    # load data&lt;br /&gt;
    elev = sio.loadmat('elev.mat')&lt;br /&gt;
    # retrive the actual array. the data set contains also the spatial reference&lt;br /&gt;
    elev.get('map_data')&lt;br /&gt;
    data = elev.get('map_data')&lt;br /&gt;
    # a first simple plot&lt;br /&gt;
    import pylab&lt;br /&gt;
    pylab.plot(data)&lt;br /&gt;
    pylab.show()&lt;br /&gt;
    # the contour plot&lt;br /&gt;
    pylab.contour(data)&lt;br /&gt;
    # obviously data needs to ne reversed&lt;br /&gt;
    import numpy as np&lt;br /&gt;
    data_rev = data[::-1]&lt;br /&gt;
    pylab.contour(data_rev)&lt;br /&gt;
    # =&amp;gt; this is a quick plot. basemap mapping may provide a nicer map!&lt;br /&gt;
    #######&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python-SWIG-GRASS interface ===&lt;br /&gt;
There is a prototype GRASS-SWIG interface available (thanks to Sajith VK), find it in GRASS 6-CVS: '''swig/python/'''. Draft documentation is [http://download.osgeo.org/grass/grass6_progman/swig/ here]. It now wraps both raster and vector data C functions plus the general GIS (G_*()) functions.&lt;br /&gt;
&lt;br /&gt;
Background: [http://www.swig.org SWIG] (Simplified Wrapper and Interface Generator) is: &lt;br /&gt;
&lt;br /&gt;
* A compiler that turns ANSI C/C++ declarations into scripting language interfaces.&lt;br /&gt;
* Completely automated (produces a fully working Python extension module). &lt;br /&gt;
* Language neutral. SWIG can also target Tcl, Perl, Guile, MATLAB (try PyLab+Matplotlib from python), etc... &lt;br /&gt;
* Attempts to eliminate the tedium of writing extension modules.&lt;br /&gt;
&lt;br /&gt;
==== Python-SWIG examples ====&lt;br /&gt;
&lt;br /&gt;
* Latest and greatest: [[http://trac.osgeo.org/grass/browser/grass/trunk/scripts GRASS 7 Python scripts]]&lt;br /&gt;
&lt;br /&gt;
* [[PythonSwigExamples|More complicated examples]]&lt;br /&gt;
&lt;br /&gt;
Sample script for GRASS 6 raster access (use within GRASS, Spearfish session):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Raster Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_cell2(input, '')&lt;br /&gt;
&lt;br /&gt;
# determine the inputmap type (CELL/FCELL/DCELL) */&lt;br /&gt;
data_type = grass.G_raster_map_type(input, mapset)&lt;br /&gt;
&lt;br /&gt;
infd = grass.G_open_cell_old(input, mapset)&lt;br /&gt;
inrast = grass.G_allocate_raster_buf(data_type)&lt;br /&gt;
&lt;br /&gt;
rown = 0&lt;br /&gt;
while True:&lt;br /&gt;
    myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)&lt;br /&gt;
    print rown, myrow[0:10]&lt;br /&gt;
    rown += 1&lt;br /&gt;
    if rown == 476:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
grass.G_close_cell(inrast)&lt;br /&gt;
grass.G_free(cell)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sample script for vector access (use within GRASS, Spearfish session):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# run within GRASS Spearfish session&lt;br /&gt;
# run this before starting python to append module search path:&lt;br /&gt;
#   export PYTHONPATH=/usr/src/grass70/swig/python&lt;br /&gt;
#   check with &amp;quot;import sys; sys.path&amp;quot;&lt;br /&gt;
# or:&lt;br /&gt;
#   sys.path.append(&amp;quot;/usr/src/grass70/swig/python&amp;quot;)&lt;br /&gt;
# FIXME: install the grass bindings in $GISBASE/lib/ ?&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
from grass.lib import vector as grassvect&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Vector Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_vector2(input,'')&lt;br /&gt;
&lt;br /&gt;
# define map structure&lt;br /&gt;
map = grassvect.Map_info()&lt;br /&gt;
&lt;br /&gt;
# define open level (level 2: topology)&lt;br /&gt;
grassvect.Vect_set_open_level (2)&lt;br /&gt;
&lt;br /&gt;
# open existing map&lt;br /&gt;
grassvect.Vect_open_old(map, input, mapset)&lt;br /&gt;
&lt;br /&gt;
# query&lt;br /&gt;
print 'Vect map: ', input&lt;br /&gt;
print 'Vect is 3D: ', grassvect.Vect_is_3d (map)&lt;br /&gt;
print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)&lt;br /&gt;
print 'Map Scale:  1:', grassvect.Vect_get_scale(map)&lt;br /&gt;
print 'Number of areas:', grassvect.Vect_get_num_areas(map)&lt;br /&gt;
&lt;br /&gt;
# close map&lt;br /&gt;
grassvect.Vect_close(map)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== TODO ====&lt;br /&gt;
&lt;br /&gt;
* Implement modules support in a Python class using --interface-description and a Python-XML parser. This should be a generic class with module's name as parameter, returning back an object which describes the module (description, flags, parameters, status of not/required). See [http://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/ GRASS 6 wxPython interface] for inspiration. Important is to auto-generate the GRASS-Python class at compile time with a Python script.&lt;br /&gt;
&lt;br /&gt;
=== Python-GRASS add-ons ===&lt;br /&gt;
&lt;br /&gt;
Stand-alone addons:&lt;br /&gt;
&lt;br /&gt;
# Jáchym Čepický's G-ps.map, a GUI to typeset printable maps with ps.map (http://193.84.38.2/~jachym/index.py?cat=gpsmap)&lt;br /&gt;
# Jáchym Čepický's v.pydigit, a GUI to v.edit (http://les-ejk.cz/?cat=vpydigit)&lt;br /&gt;
# Jáchym Čepický's PyWPS, GRASS-Web Processing Service (http://pywps.wald.intevation.org)&lt;br /&gt;
&lt;br /&gt;
=== Using GRASS gui.tcl in Python ===&lt;br /&gt;
&lt;br /&gt;
Here is some example code to use the grass automatically generated guis in python code. This could (should) all be bundled up and abstracted away so that the implementation can be replaced later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Tkinter&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# Startup (once):&lt;br /&gt;
&lt;br /&gt;
tk = Tkinter.Tk()&lt;br /&gt;
tk.eval (&amp;quot;wm withdraw .&amp;quot;)&lt;br /&gt;
tk.eval (&amp;quot;source $env(GISBASE)/etc/gui.tcl&amp;quot;)&lt;br /&gt;
# Here you could do various things to change what the gui does&lt;br /&gt;
# See gui.tcl and README.GUI&lt;br /&gt;
&lt;br /&gt;
# Make a gui (per dialog)&lt;br /&gt;
# This sets up a window for the command.&lt;br /&gt;
# This can be different to integrate with tkinter:&lt;br /&gt;
tk.eval ('set path &amp;quot;.dialog$dlg&amp;quot;')&lt;br /&gt;
tk.eval ('toplevel .dialog$dlg')&lt;br /&gt;
# Load the code for this command:&lt;br /&gt;
fd = os.popen (&amp;quot;d.vect --tcltk&amp;quot;)&lt;br /&gt;
gui = fd.read()&lt;br /&gt;
# Run it&lt;br /&gt;
tk.eval(gui)&lt;br /&gt;
dlg = tk.eval('set dlg') # This is used later to get and set &lt;br /&gt;
&lt;br /&gt;
# Get the current command in the gui we just made:&lt;br /&gt;
currentcommand = tk.eval (&amp;quot;dialog_get_command &amp;quot; + dlg)&lt;br /&gt;
&lt;br /&gt;
# Set the command in the dialog we just made:&lt;br /&gt;
tk.eval (&amp;quot;dialog_set_command &amp;quot; + dlg + &amp;quot; {d.vect map=roads}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
=== General guides ===&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikibooks.org/wiki/Python_Programming/ Wikibook Python Programming]&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Quick Python tutorial] for programmers of other languages&lt;br /&gt;
: [http://wiki.python.org/moin/BeginnersGuide/Programmers More Python tutorials] for programmers&lt;br /&gt;
* [http://www.python.org/dev/peps/pep-0008/ Python programming style guide]&lt;br /&gt;
&lt;br /&gt;
=== Programming ===&lt;br /&gt;
&lt;br /&gt;
* Python and GRASS:&lt;br /&gt;
** GRASS Python interface to library functions: http://download.osgeo.org/grass/grass6_progman/swig/ based on SWIG http://www.swig.org/&lt;br /&gt;
** GRASS Python scripting library: http://download.osgeo.org/grass/grass6_progman/pythonlib.html&lt;br /&gt;
** PyWPS, GRASS-Web Processing Service http://pywps.wald.intevation.org&lt;br /&gt;
&lt;br /&gt;
* Python and OSGeo:&lt;br /&gt;
** [http://wiki.osgeo.org/wiki/OSGeo_Python_Library OSGeo Python Library]&lt;br /&gt;
&lt;br /&gt;
* Python and GDAL/OGR:&lt;br /&gt;
** [http://mapserver.gis.umn.edu/community/conferences/MUM3/workshop/python Open Source Python GIS Hacks Mum'03]&lt;br /&gt;
** http://hobu.biz/software/OSGIS_Hacks - Python OSGIS Hacks '05&lt;br /&gt;
** http://zcologia.com/news/categorylist_html?cat_id=8&lt;br /&gt;
** http://www.perrygeo.net/wordpress/?p=4&lt;br /&gt;
&lt;br /&gt;
* Python bindings to PROJ:&lt;br /&gt;
** http://www.cdc.noaa.gov/people/jeffrey.s.whitaker/python/pyproj.html&lt;br /&gt;
&lt;br /&gt;
* Python and GIS:&lt;br /&gt;
** [http://gispython.org/ Open Source GIS-Python Laboratory]&lt;br /&gt;
&lt;br /&gt;
* Python and Statistics:&lt;br /&gt;
** [http://rpy.sourceforge.net/ RPy] - Python interface to the R-statistics programming language&lt;br /&gt;
&lt;br /&gt;
* Bindings:&lt;br /&gt;
** SIP (C/C++ bindings generator) http://directory.fsf.org/all/Python-SIP.html&lt;br /&gt;
** [http://www.cython.org/ Cython] - C-Extensions for Python (compile where speed is needed)&lt;br /&gt;
&lt;br /&gt;
* Other external projects&lt;br /&gt;
** [http://www.scipy.org Scientific Python]&lt;br /&gt;
** [http://wiki.python.org/moin/NumericAndScientific Numeric and Scientific]&lt;br /&gt;
** [http://w3.pppl.gov/~hammett/comp/python/python.html Info on Python for Scientific Applications]&lt;br /&gt;
&lt;br /&gt;
=== Presentations ===&lt;br /&gt;
&lt;br /&gt;
From FOSS4G2006:&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=136&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 A Python sweeps in the GRASS] - A. Frigeri 2006&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=67&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 GRASS goes web: PyWPS] - J. Cepicky 2006&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Linking to other languages]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>⚠️Sonja</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=10478</id>
		<title>GRASS and Python</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=10478"/>
		<updated>2010-03-05T16:47:42Z</updated>

		<summary type="html">&lt;p&gt;⚠️Sonja: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''(for discussions on the new GRASS GUI, see [[GRASS GUI|here]])''&lt;br /&gt;
&lt;br /&gt;
==Python SIGs==&lt;br /&gt;
Python Special Interest Groups are focused collaborative efforts to develop, improve, or maintain specific Python resources. Each SIG has a charter, a coordinator, a mailing list, and a directory on the Python website. SIG membership is informal, defined by subscription to the SIG's mailing list. Anyone can join a SIG, and participate in the development discussions via the SIG's mailing list. Below is the list of currently active Python SIGs, with links to their resources. &lt;br /&gt;
&lt;br /&gt;
See more at http://www.python.org/community/sigs/&lt;br /&gt;
&lt;br /&gt;
==Writing Python scripts in GRASS==&lt;br /&gt;
&lt;br /&gt;
Python is a programming language which is more powerful than shell scripting but easier and more forgiving than C.&lt;br /&gt;
The Python script can contain simple module description definitions which will be processed with {{cmd|g.parser}}, as shown in the example below. In this way with no extra coding a GUI can be built, inputs checked, and a skeleton help page can be generated automatically. In addition it adds links to the GRASS message translation system.&lt;br /&gt;
For code which needs access to the power of C, you can access the GRASS C library functions via the SWIG interface.&lt;br /&gt;
&lt;br /&gt;
* GRASS Python interface to library functions: http://download.osgeo.org/grass/grass6_progman/swig/&lt;br /&gt;
* GRASS Python scripting library: http://download.osgeo.org/grass/grass6_progman/pythonlib.html&lt;br /&gt;
&lt;br /&gt;
Code style: Have a look at [http://trac.osgeo.org/grass/browser/grass/trunk/SUBMITTING_PYTHON SUBMITTING_PYTHON].&lt;br /&gt;
&lt;br /&gt;
=== Creating Python scripts that run in GRASS under MS-Windows ===&lt;br /&gt;
&lt;br /&gt;
The environment variables have to be set as follows:&lt;br /&gt;
 GISBASE= C:\GRASS-64&lt;br /&gt;
 GISRC= C:\Documents and Settings\user\.grassrc6&lt;br /&gt;
 LD_LIBRARY_PATH= C:\GRASS-64\lib&lt;br /&gt;
 PATH= C:\GRASS-64\etc;C:\GRASS-64\etc\python;C:\GRASS-64\lib;C:\GRASS-64\bin;C:\GRASS-64\extralib;C:\GRASS-4-SVN\msys\bin;C:\Python26;&lt;br /&gt;
 PYTHONLIB= C:\Python26&lt;br /&gt;
 PYTHONPATH= C:\GRASS-64\etc\python&lt;br /&gt;
 GRASS_SH= C:\GRASS-4-SVN\msys\bin\sh.exe&lt;br /&gt;
&lt;br /&gt;
Some hints:&lt;br /&gt;
&lt;br /&gt;
# The Python interpreter (python.exe) needs to be in the PATH&lt;br /&gt;
# Python needs to be associated with the .py extension&lt;br /&gt;
# PATHEXT needs to include .py if you want to be able to omit the extension&lt;br /&gt;
# PYTHONPATH needs to be set to %WINGISBASE%\etc\python&lt;br /&gt;
&lt;br /&gt;
1-3 should be taken care of by the Python installer. 4 needs to be done by the startup (currently, this doesn't appear to be the case on MS-Windows).&lt;br /&gt;
&lt;br /&gt;
=== Running external commands from Python ===&lt;br /&gt;
For information on running external commands from Python, see:&lt;br /&gt;
http://docs.python.org/lib/module-subprocess.html&lt;br /&gt;
&lt;br /&gt;
Avoid using the older os.* functions. Section 17.1.3 lists equivalents&lt;br /&gt;
using the Popen() interface, which is more robust (particularly on&lt;br /&gt;
Windows).&lt;br /&gt;
&lt;br /&gt;
=== Examples ===&lt;br /&gt;
&lt;br /&gt;
==== Display example ====&lt;br /&gt;
Example of Python script, which is processed by g.parser:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
#&lt;br /&gt;
############################################################################&lt;br /&gt;
#&lt;br /&gt;
# MODULE:      d.shadedmap&lt;br /&gt;
# AUTHOR(S):   Unknown; updated to GRASS 5.7 by Michael Barton&lt;br /&gt;
#              Converted to Python by Glynn Clements&lt;br /&gt;
# PURPOSE:     Uses d.his to drape a color raster over a shaded relief map&lt;br /&gt;
# COPYRIGHT:   (C) 2004,2008,2009 by the GRASS Development Team&lt;br /&gt;
#&lt;br /&gt;
#              This program is free software under the GNU General Public&lt;br /&gt;
#              License (&amp;gt;=v2). Read the file COPYING that comes with GRASS&lt;br /&gt;
#              for details.&lt;br /&gt;
#&lt;br /&gt;
#############################################################################&lt;br /&gt;
&lt;br /&gt;
#%Module&lt;br /&gt;
#% description: Drapes a color raster over a shaded relief map using d.his&lt;br /&gt;
#%End&lt;br /&gt;
#%option&lt;br /&gt;
#% key: reliefmap&lt;br /&gt;
#% type: string&lt;br /&gt;
#% gisprompt: old,cell,raster&lt;br /&gt;
#% description: Name of shaded relief or aspect map&lt;br /&gt;
#% required : yes&lt;br /&gt;
#%end&lt;br /&gt;
#%option&lt;br /&gt;
#% key: drapemap&lt;br /&gt;
#% type: string&lt;br /&gt;
#% gisprompt: old,cell,raster&lt;br /&gt;
#% description: Name of raster to drape over relief map&lt;br /&gt;
#% required : yes&lt;br /&gt;
#%end&lt;br /&gt;
#%option&lt;br /&gt;
#% key: brighten&lt;br /&gt;
#% type: integer&lt;br /&gt;
#% description: Percent to brighten&lt;br /&gt;
#% options: -99-99&lt;br /&gt;
#% answer: 0&lt;br /&gt;
#%end&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
from grass.script import core as grass&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    drape_map = options['drapemap']&lt;br /&gt;
    relief_map = options['reliefmap']&lt;br /&gt;
    brighten = options['brighten']&lt;br /&gt;
    ret = grass.run_command(&amp;quot;d.his&amp;quot;, h_map = drape_map,  i_map = relief_map, brighten = brighten)&lt;br /&gt;
    sys.exit(ret)&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    options, flags = grass.parser()&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Example for embedding r.mapcalc (map algebra) ====&lt;br /&gt;
&lt;br /&gt;
grass.mapcalc() accepts a template string followed by keyword&lt;br /&gt;
arguments for the substitutions, e.g. (code snippets):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
grass.mapcalc(&amp;quot;${out} = ${rast1} + ${rast2}&amp;quot;,&lt;br /&gt;
              out = options['output'],&lt;br /&gt;
              rast1 = options['raster1'],&lt;br /&gt;
              rast2 = options['raster2'])&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''Best practice'': first copy all of the options[] into separate variables at the beginning of main(), i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def main():&lt;br /&gt;
    output = options['output']&lt;br /&gt;
    raster1 = options['raster1']&lt;br /&gt;
    raster2 = options['raster2']&lt;br /&gt;
 &lt;br /&gt;
    ...&lt;br /&gt;
 &lt;br /&gt;
    grass.mapcalc(&amp;quot;${out} = ${rast1} + ${rast2}&amp;quot;,&lt;br /&gt;
                  out = output,&lt;br /&gt;
                  rast1 = raster1,&lt;br /&gt;
                  rast2 = raster2)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Python extensions for GRASS GIS==&lt;br /&gt;
=== wxPython GUI development for GRASS ===&lt;br /&gt;
&lt;br /&gt;
* See the [[GRASS GUI]] wiki page&lt;br /&gt;
&lt;br /&gt;
=== GRASS Python library ===&lt;br /&gt;
&lt;br /&gt;
See [http://download.osgeo.org/grass/grass6_progman/pythonlib.html GRASS Python library]&lt;br /&gt;
&lt;br /&gt;
==== Interfacing with NumPy ====&lt;br /&gt;
&lt;br /&gt;
''Glynn writes:''&lt;br /&gt;
&lt;br /&gt;
The grass.script.array module defines a class &amp;quot;array&amp;quot; which is a&lt;br /&gt;
subclass of numpy.memmap with .read() and .write() methods to&lt;br /&gt;
read/write the underlying file via r.out.bin/r.in.bin.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    import grass.script.array as garray&lt;br /&gt;
    a = garray.array()&lt;br /&gt;
    a.read(&amp;quot;elevation.dem&amp;quot;)&lt;br /&gt;
    b = garray.array()&lt;br /&gt;
    b[...] = (a / 50).astype(int) * 50    # or whatever&lt;br /&gt;
    b.write(&amp;quot;elev.50m&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The size of the array is taken from the current region.&lt;br /&gt;
&lt;br /&gt;
The main drawback of using numpy is that you're limited by available&lt;br /&gt;
memory. Using a subclass of numpy.memmap lets you use files which may&lt;br /&gt;
be much larger, but processing the entire array in one go is likely to&lt;br /&gt;
produce in-memory results of a similar size.&lt;br /&gt;
&lt;br /&gt;
One may also use the scipy matlab interface:&lt;br /&gt;
    &lt;br /&gt;
    ### SH: in GRASS ###&lt;br /&gt;
    r.out.mat input=elevation output=elev.mat&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
    ### PY ###&lt;br /&gt;
    import scipy.io as sio&lt;br /&gt;
    # load data&lt;br /&gt;
    elev = sio.loadmat('elev.mat')&lt;br /&gt;
    # retrive the actual array. the data set contains also the spatial reference&lt;br /&gt;
    elev.get('map_data')&lt;br /&gt;
    data = elev.get('map_data')&lt;br /&gt;
    # a first simple plot&lt;br /&gt;
    import pylab&lt;br /&gt;
    pylab.plot(data)&lt;br /&gt;
    pylab.show()&lt;br /&gt;
    # the contour plot&lt;br /&gt;
    pylab.contour(data)&lt;br /&gt;
    # obviously data needs to ne reversed&lt;br /&gt;
    import numpy as np&lt;br /&gt;
    data_rev = data[::-1]&lt;br /&gt;
    pylab.contour(data_rev)&lt;br /&gt;
    # =&amp;gt; this is a quick plot. basemap mapping may provide a nicer map!&lt;br /&gt;
    #######&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Python-SWIG-GRASS interface ===&lt;br /&gt;
There is a prototype GRASS-SWIG interface available (thanks to Sajith VK), find it in GRASS 6-CVS: '''swig/python/'''. Draft documentation is [http://download.osgeo.org/grass/grass6_progman/swig/ here]. It now wraps both raster and vector data C functions plus the general GIS (G_*()) functions.&lt;br /&gt;
&lt;br /&gt;
Background: [http://www.swig.org SWIG] (Simplified Wrapper and Interface Generator) is: &lt;br /&gt;
&lt;br /&gt;
* A compiler that turns ANSI C/C++ declarations into scripting language interfaces.&lt;br /&gt;
* Completely automated (produces a fully working Python extension module). &lt;br /&gt;
* Language neutral. SWIG can also target Tcl, Perl, Guile, MATLAB (try PyLab+Matplotlib from python), etc... &lt;br /&gt;
* Attempts to eliminate the tedium of writing extension modules.&lt;br /&gt;
&lt;br /&gt;
==== Python-SWIG examples ====&lt;br /&gt;
&lt;br /&gt;
* Latest and greatest: [[http://trac.osgeo.org/grass/browser/grass/trunk/scripts GRASS 7 Python scripts]]&lt;br /&gt;
&lt;br /&gt;
* [[PythonSwigExamples|More complicated examples]]&lt;br /&gt;
&lt;br /&gt;
Sample script for GRASS 6 raster access (use within GRASS, Spearfish session):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Raster Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_cell2(input, '')&lt;br /&gt;
&lt;br /&gt;
# determine the inputmap type (CELL/FCELL/DCELL) */&lt;br /&gt;
data_type = grass.G_raster_map_type(input, mapset)&lt;br /&gt;
&lt;br /&gt;
infd = grass.G_open_cell_old(input, mapset)&lt;br /&gt;
inrast = grass.G_allocate_raster_buf(data_type)&lt;br /&gt;
&lt;br /&gt;
rown = 0&lt;br /&gt;
while True:&lt;br /&gt;
    myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)&lt;br /&gt;
    print rown, myrow[0:10]&lt;br /&gt;
    rown += 1&lt;br /&gt;
    if rown == 476:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
grass.G_close_cell(inrast)&lt;br /&gt;
grass.G_free(cell)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sample script for vector access (use within GRASS, Spearfish session):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# run within GRASS Spearfish session&lt;br /&gt;
# run this before starting python to append module search path:&lt;br /&gt;
#   export PYTHONPATH=/usr/src/grass70/swig/python&lt;br /&gt;
#   check with &amp;quot;import sys; sys.path&amp;quot;&lt;br /&gt;
# or:&lt;br /&gt;
#   sys.path.append(&amp;quot;/usr/src/grass70/swig/python&amp;quot;)&lt;br /&gt;
# FIXME: install the grass bindings in $GISBASE/lib/ ?&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
from grass.lib import vector as grassvect&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Vector Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_vector2(input,'')&lt;br /&gt;
&lt;br /&gt;
# define map structure&lt;br /&gt;
map = grassvect.Map_info()&lt;br /&gt;
&lt;br /&gt;
# define open level (level 2: topology)&lt;br /&gt;
grassvect.Vect_set_open_level (2)&lt;br /&gt;
&lt;br /&gt;
# open existing map&lt;br /&gt;
grassvect.Vect_open_old(map, input, mapset)&lt;br /&gt;
&lt;br /&gt;
# query&lt;br /&gt;
print 'Vect map: ', input&lt;br /&gt;
print 'Vect is 3D: ', grassvect.Vect_is_3d (map)&lt;br /&gt;
print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)&lt;br /&gt;
print 'Map Scale:  1:', grassvect.Vect_get_scale(map)&lt;br /&gt;
print 'Number of areas:', grassvect.Vect_get_num_areas(map)&lt;br /&gt;
&lt;br /&gt;
# close map&lt;br /&gt;
grassvect.Vect_close(map)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== TODO ====&lt;br /&gt;
&lt;br /&gt;
* Implement modules support in a Python class using --interface-description and a Python-XML parser. This should be a generic class with module's name as parameter, returning back an object which describes the module (description, flags, parameters, status of not/required). See [http://trac.osgeo.org/grass/browser/grass/trunk/gui/wxpython/ GRASS 6 wxPython interface] for inspiration. Important is to auto-generate the GRASS-Python class at compile time with a Python script.&lt;br /&gt;
&lt;br /&gt;
=== Python-GRASS add-ons ===&lt;br /&gt;
&lt;br /&gt;
Stand-alone addons:&lt;br /&gt;
&lt;br /&gt;
# Jáchym Čepický's G-ps.map, a GUI to typeset printable maps with ps.map (http://193.84.38.2/~jachym/index.py?cat=gpsmap)&lt;br /&gt;
# Jáchym Čepický's v.pydigit, a GUI to v.edit (http://les-ejk.cz/?cat=vpydigit)&lt;br /&gt;
# Jáchym Čepický's PyWPS, GRASS-Web Processing Service (http://pywps.wald.intevation.org)&lt;br /&gt;
&lt;br /&gt;
=== Using GRASS gui.tcl in Python ===&lt;br /&gt;
&lt;br /&gt;
Here is some example code to use the grass automatically generated guis in python code. This could (should) all be bundled up and abstracted away so that the implementation can be replaced later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Tkinter&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# Startup (once):&lt;br /&gt;
&lt;br /&gt;
tk = Tkinter.Tk()&lt;br /&gt;
tk.eval (&amp;quot;wm withdraw .&amp;quot;)&lt;br /&gt;
tk.eval (&amp;quot;source $env(GISBASE)/etc/gui.tcl&amp;quot;)&lt;br /&gt;
# Here you could do various things to change what the gui does&lt;br /&gt;
# See gui.tcl and README.GUI&lt;br /&gt;
&lt;br /&gt;
# Make a gui (per dialog)&lt;br /&gt;
# This sets up a window for the command.&lt;br /&gt;
# This can be different to integrate with tkinter:&lt;br /&gt;
tk.eval ('set path &amp;quot;.dialog$dlg&amp;quot;')&lt;br /&gt;
tk.eval ('toplevel .dialog$dlg')&lt;br /&gt;
# Load the code for this command:&lt;br /&gt;
fd = os.popen (&amp;quot;d.vect --tcltk&amp;quot;)&lt;br /&gt;
gui = fd.read()&lt;br /&gt;
# Run it&lt;br /&gt;
tk.eval(gui)&lt;br /&gt;
dlg = tk.eval('set dlg') # This is used later to get and set &lt;br /&gt;
&lt;br /&gt;
# Get the current command in the gui we just made:&lt;br /&gt;
currentcommand = tk.eval (&amp;quot;dialog_get_command &amp;quot; + dlg)&lt;br /&gt;
&lt;br /&gt;
# Set the command in the dialog we just made:&lt;br /&gt;
tk.eval (&amp;quot;dialog_set_command &amp;quot; + dlg + &amp;quot; {d.vect map=roads}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
=== General guides ===&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikibooks.org/wiki/Python_Programming/ Wikibook Python Programming]&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Quick Python tutorial] for programmers of other languages&lt;br /&gt;
: [http://wiki.python.org/moin/BeginnersGuide/Programmers More Python tutorials] for programmers&lt;br /&gt;
* [http://www.python.org/dev/peps/pep-0008/ Python programming style guide]&lt;br /&gt;
&lt;br /&gt;
=== Programming ===&lt;br /&gt;
&lt;br /&gt;
* Python and GRASS:&lt;br /&gt;
** GRASS Python interface to library functions: http://download.osgeo.org/grass/grass6_progman/swig/ based on SWIG http://www.swig.org/&lt;br /&gt;
** GRASS Python scripting library: http://download.osgeo.org/grass/grass6_progman/pythonlib.html&lt;br /&gt;
** PyWPS, GRASS-Web Processing Service http://pywps.wald.intevation.org&lt;br /&gt;
&lt;br /&gt;
* Python and OSGeo:&lt;br /&gt;
** [http://wiki.osgeo.org/wiki/OSGeo_Python_Library OSGeo Python Library]&lt;br /&gt;
&lt;br /&gt;
* Python and GDAL/OGR:&lt;br /&gt;
** [http://mapserver.gis.umn.edu/community/conferences/MUM3/workshop/python Open Source Python GIS Hacks Mum'03]&lt;br /&gt;
** http://hobu.biz/software/OSGIS_Hacks - Python OSGIS Hacks '05&lt;br /&gt;
** http://zcologia.com/news/categorylist_html?cat_id=8&lt;br /&gt;
** http://www.perrygeo.net/wordpress/?p=4&lt;br /&gt;
&lt;br /&gt;
* Python bindings to PROJ:&lt;br /&gt;
** http://www.cdc.noaa.gov/people/jeffrey.s.whitaker/python/pyproj.html&lt;br /&gt;
&lt;br /&gt;
* Python and GIS:&lt;br /&gt;
** [http://gispython.org/ Open Source GIS-Python Laboratory]&lt;br /&gt;
&lt;br /&gt;
* Python and Statistics:&lt;br /&gt;
** [http://rpy.sourceforge.net/ RPy] - Python interface to the R-statistics programming language&lt;br /&gt;
&lt;br /&gt;
* Bindings:&lt;br /&gt;
** SIP (C/C++ bindings generator) http://directory.fsf.org/all/Python-SIP.html&lt;br /&gt;
** [http://www.cython.org/ Cython] - C-Extensions for Python (compile where speed is needed)&lt;br /&gt;
&lt;br /&gt;
* Other external projects&lt;br /&gt;
** [http://www.scipy.org Scientific Python]&lt;br /&gt;
** [http://wiki.python.org/moin/NumericAndScientific Numeric and Scientific]&lt;br /&gt;
** [http://w3.pppl.gov/~hammett/comp/python/python.html Info on Python for Scientific Applications]&lt;br /&gt;
&lt;br /&gt;
=== Presentations ===&lt;br /&gt;
&lt;br /&gt;
From FOSS4G2006:&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=136&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 A Python sweeps in the GRASS] - A. Frigeri 2006&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=67&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 GRASS goes web: PyWPS] - J. Cepicky 2006&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:Linking to other languages]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>⚠️Sonja</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Using_Eclipse_to_develop_GRASS_Python_programs&amp;diff=10474</id>
		<title>Using Eclipse to develop GRASS Python programs</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Using_Eclipse_to_develop_GRASS_Python_programs&amp;diff=10474"/>
		<updated>2010-03-05T15:56:25Z</updated>

		<summary type="html">&lt;p&gt;⚠️Sonja: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= How to use Eclipse to develop Python scripts that access GRASS object =&lt;br /&gt;
 &lt;br /&gt;
Recent releases of GRASS have emphasized the use of Python as the language of choice for developing scripts which access GRASS objects and can be used to automate operations without GRASS running.&lt;br /&gt;
 &lt;br /&gt;
This short tutorial shows how to set up a complete development environment using the Eclipse IDE to develop, debug and run Python programs that access GRASS objects. These instructions apply to MS-Windows and Linux, and probably Mac as well, since all the packages required are open source software which runs on all three platforms.&lt;br /&gt;
&lt;br /&gt;
Please note that this is not an Eclipse, nor a Python, nor a GRASS tutorial. It is just a description on how to get all the above to work together. It assumes some (but not much, because I don't have much!) knowledge of all the above.&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites (Release versions are as at the time of writing) ===&lt;br /&gt;
 &lt;br /&gt;
* GRASS 6.4 and Python 2.6.x&lt;br /&gt;
* Eclipse 3.4.x&lt;br /&gt;
* Pydev 1.4.5 Eclipse plug-in for Python&lt;br /&gt;
* Optionally, other plugins for Eclipse&lt;br /&gt;
 &lt;br /&gt;
==== GRASS 6.4.0RC5 and Python 2.6.x ====&lt;br /&gt;
&lt;br /&gt;
		Many Linux distributions already include GRASS in their packaging but you must ensure you download the latest GRASS 6.4.0 release for Linux, MS-Windows, and Mac, available in binary (executable) from the GRASS {{website|download|download site}}, and install it as instructed for your platform. On Windows install the stand-alone WinGRASS and not the OSGeo4W GRASS version. You will also need to download Python 2.6 for your platform from the [http://www.python.org Python.org site] and install it as required for your platform making a note of where the python executable (python.exe in MS-Windows) is installed. Most recent Linux already come with Python 2.6.2 installed. &lt;br /&gt;
&lt;br /&gt;
==== Eclipse ====&lt;br /&gt;
&lt;br /&gt;
		Eclipse 3.4.2 is the minimum version recommended, but other releases could work as well. Download it from [http://www.eclipse.org the Eclipse download page]. The Ganymede 3.4.2 release for Java developers is fine (85MB). Installing Eclipse is very easy because installations consists simply of unpacking the download package in a directory of your choice.&lt;br /&gt;
To avoid permission problems in Linux, install Eclipse in your Home directory or a subdirectory.&lt;br /&gt;
		&lt;br /&gt;
==== Pydev ====&lt;br /&gt;
Pydev is an Eclipse plugin that adapts the Eclipse platform to the specific needs of Python program  development, debugging and testing. It is not the only Python plugin available, but the one largely recommended.&lt;br /&gt;
The current release is 1.4.5 and to install it you should use the Eclipse Update Manager mechanism, as detailed below.&lt;br /&gt;
&lt;br /&gt;
Open the Eclipse platform and click on the Help &amp;amp;rarr; Software Updates menu entry, click on the Available Software tab and click on the Add Site button. This will open a dialog box where you insert the following URL:  http://pydev.org/updates/ . Then press OK and follow the instructions. This will result in the Pydev plug-in being automatically downloaded. Click on the install button to install it among your other Eclipse plug-ins. Furthermore it will automatically inform you in future when new updates are available. The Home page for Pydev is: http://pydev.org/ .&lt;br /&gt;
At this point you have all the software pre-requisites installed, ready for the next step.&lt;br /&gt;
&lt;br /&gt;
==== Creating a new project ====&lt;br /&gt;
&lt;br /&gt;
When you first open the Eclipse platform after a new installation you will be asked to set-up a workspace, which will normally be in your home directory by default, then you will see  a Welcome screen with various buttons. Click on the one that opens the Eclipse workspace, which will be empty and probably be Java oriented.&lt;br /&gt;
To change it to be Python oriented you must open what in Eclipse is called a &amp;quot;perspective&amp;quot;, which is a combination of views and windows which suits the plug-in you are actually using at any one time. So, go to the Window &amp;amp;rarr; Open Perspective sub-menu and select Pydev. This will open the Pydev perspective where most of your development work will be done, and since new development starts with a new Project, now go to the File &amp;amp;rarr; New menu and select Pydev Project, and follow the prompts to create a new empty Python project which we will name Myproject. &lt;br /&gt;
&lt;br /&gt;
==== Configuring Eclipse and Pydev ====&lt;br /&gt;
&lt;br /&gt;
Eclipse is highly configurable, but for our purpose we will only look at the configuration required for Python use. &lt;br /&gt;
There are three preferences menus you should know,  the Window (or Eclipse) Preferences menu, the Project Properties menu, and the Run or Debug Configuration menu, but for our needs we will just look at Window and Run Configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Open the Window &amp;amp;rarr; Preferences menu, expand the Pydev entry and select Interpreter - Python. Sometime Eclipse can automatically detect the location of your Python interpreter, in which case it will appear in the top right box: but if it didn't simply add it via the New button (remember you made a note of its location earlier on!).&lt;br /&gt;
In the bottom box add the following New Folders to the ones automatically added by Eclipse, and which point to the GRASS libraries (in Mac(?) they will be located within the GRASS installation directory tree):&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
 /usr/lib/grass64/etc&lt;br /&gt;
 /usr/lib/grass64/etc/python&lt;br /&gt;
 /usr/lib/grass64/bin&lt;br /&gt;
 /usr/lib/grass64/scripts&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
 C:\GRASS-64\etc&lt;br /&gt;
 C:\GRASS-64\etc\python&lt;br /&gt;
 C:\GRASS-64\bin &lt;br /&gt;
&lt;br /&gt;
then press Apply and OK. Finally go to the Run  Configurations menu and create a new entry for test.py as follows:&lt;br /&gt;
&lt;br /&gt;
* Click on Python Run, then click on the New configuration icon, the first at the top. Provide a Name, Project and Module names either manually or by browsing and press Apply to create the new configuration.&lt;br /&gt;
&lt;br /&gt;
* Click on the Environment tab and enter the following variables and values, keeping in mind that as shown they reflect my configuration.When you start GRASS it sets most of these variables but since you now want to run programs without GRASS itself running, you will have to set them yourself and find the equivalent locations for your specific configuration. If you have trouble do the following: in Windows or Linux (and Mac?) start GRASS  and in the GRASS command shell type 'export' without quotes or parameters. This will list all the variables and their values as they apply to your GRASS environment, but don't be scared by their number, just look up the few I have listed then adjust their values  accordingly: &lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
 GISBASE=/usr/lib/grass64&lt;br /&gt;
 GISRC=/home/george/.grassrc6 		&lt;br /&gt;
 LD_LIBRARY_PATH=/usr/lib/grass64/lib 		&lt;br /&gt;
 PATH=/home/george/local/jdk1.6.0_13/lib:/home/george/local/jdk1.6.0_13/jre:/home/george/local/jdk1.6.0_13/jre/bin/java/home/george/local/jdk1.6.0_13/jre/bin:/usr/lib/grass64:/usr/lib/grass64/bin:/usr/lib/python2.6:/usr/lib/grass64/lib:usr/lib/grass64/scripts:/usr/lib/grass64/etc:/usr/lib/grass64/etc/python:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games  &lt;br /&gt;
 PYTHONPATH=/usr/lib/grass64/etc:/usr/lib/grass64/etc/python:/usr/lib/grass64/lib:/usr/lib/grass64/bin:/usr/lib/grass64/scripts:/usr/lib/python2.6&lt;br /&gt;
 PYTHONLIB=/usr/lib/python2.6&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
 GISBASE= C:\GRASS-64&lt;br /&gt;
 GISRC= C:\Documents and Settings\user\.grassrc6&lt;br /&gt;
 LD_LIBRARY_PATH= C:\GRASS-64\lib&lt;br /&gt;
 PATH= C:\GRASS-64\etc;C:\GRASS-64\etc\python;C:\GRASS-64\lib;C:\GRASS-64\bin;C:\GRASS-64\extralib;C:\GRASS-4-SVN\msys\bin;C:\Python26;&lt;br /&gt;
 PYTHONLIB= C:\Python26&lt;br /&gt;
 PYTHONPATH= C:\GRASS-64\etc\python&lt;br /&gt;
 GRASS_SH= C:\GRASS-4-SVN\msys\bin\sh.exe&lt;br /&gt;
&lt;br /&gt;
and Apply all of them.&lt;br /&gt;
* Now click on the Interpreter tab to verify that the interpreter has been correctly located and Pythonpath correctly set. Press OK to exit and now you are ready to run or debug your first Python program from Eclipse!&lt;br /&gt;
&lt;br /&gt;
==== Running a test program ====&lt;br /&gt;
&lt;br /&gt;
Finally create the following new Python source program by right-clicking the Myproject source tree and selecting New &amp;amp;rarr; File from the menu. Name the file test.py (including the extension) and when the empty file opens on your workspace paste the following lines:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
 import os&lt;br /&gt;
 import grass.script as grass&lt;br /&gt;
 env = grass.gisenv()&lt;br /&gt;
 print env&lt;br /&gt;
 #List all environment variables&lt;br /&gt;
 for key, value in os.environ.items(): print key, value &lt;br /&gt;
 #Print region extent&lt;br /&gt;
 r = grass.read_command(&amp;quot;g.region&amp;quot;, flags='p' )&lt;br /&gt;
 print r&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save the file and press the Run button in the Run Configuration dialog, or from the Run menu select 'Run'.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Eclipse]] in general&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
[[Category:Linking to other languages]]&lt;br /&gt;
[[Category:Python]]&lt;/div&gt;</summary>
		<author><name>⚠️Sonja</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Using_Eclipse_to_develop_GRASS_Python_programs&amp;diff=10204</id>
		<title>Using Eclipse to develop GRASS Python programs</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Using_Eclipse_to_develop_GRASS_Python_programs&amp;diff=10204"/>
		<updated>2010-01-18T12:46:58Z</updated>

		<summary type="html">&lt;p&gt;⚠️Sonja: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;          &lt;br /&gt;
= How to use Eclipse to develop Python scripts that access GRASS object =&lt;br /&gt;
 &lt;br /&gt;
Recent releases of GRASS have emphasised the use of Python as the language of choice for developing scripts which access GRASS objects and can be used to automate operations without GRASS running.&lt;br /&gt;
 &lt;br /&gt;
This short tutorial shows how to set up a complete development environment using the Eclipse IDE to develop, debug and run Python programs that access GRASS objects. These instructions apply to MS-Windows and Linux, and probably Mac as well, since all the packages required are open source software which runs on all three platforms.&lt;br /&gt;
&lt;br /&gt;
Please note that this is not an Eclipse, nor a Python, nor a GRASS tutorial. It is just a description on how to get all the above to work together. It assumes some (but not much, because I don't have much!) knowledge of all the above.&lt;br /&gt;
&lt;br /&gt;
=== Prerequisites (Release versions are as at the time of writing) ===&lt;br /&gt;
 &lt;br /&gt;
* GRASS 6.4 and Python 2.6.x&lt;br /&gt;
* Eclipse 3.4.x&lt;br /&gt;
* Pydev 1.4.5 Eclipse plug-in for Python&lt;br /&gt;
* Optionally, other plugins for Eclipse&lt;br /&gt;
 &lt;br /&gt;
==== GRASS 6.4.0RC4 and Python 2.6.x ====&lt;br /&gt;
&lt;br /&gt;
		Many Linux distributions already include GRASS in their packaging but you must ensure you download the latest (GRASS 6.4.0RC4) release for Linux, MS-Windows, and Mac, available in binary (executable) from the GRASS {{website|download|download site}}, and install it as instructed for your platform. On Windows install the stand-alone WinGRASS and not the OSGeo4W GRASS version. You will also need to download Python 2.6 for your platform from the [http://www.python.org Python.org site] and install it as required for your platform making a note of where the python executable (python.exe in MS-Windows) is installed. Most recent Linux already come with Python 2.6.2 installed. &lt;br /&gt;
&lt;br /&gt;
==== Eclipse ====&lt;br /&gt;
&lt;br /&gt;
		Eclipse 3.4.2 is the minimum version recommended, but other releases could work as well. Download it from [http://www.eclipse.org the Eclipse download page]. The Ganymede 3.4.2 release for Java developers is fine (85MB). Installing Eclipse is very easy because installations consists simply of unpacking the download package in a directory of your choice.&lt;br /&gt;
To avoid permission problems in Linux, install Eclipse in your Home directory or a subdirectory.&lt;br /&gt;
		&lt;br /&gt;
==== Pydev ====&lt;br /&gt;
Pydev is an Eclipse plugin that adapts the Eclipse platform to the specific needs of Python program  development, debugging and testing. It is not the only Python plugin available, but the one largely recommended.&lt;br /&gt;
The current release is 1.4.5 and to install it you should use the Eclipse Update Manager mechanism, as detailed below.&lt;br /&gt;
&lt;br /&gt;
Open the Eclipse platform and click on the Help &amp;amp;rarr; Software Updates menu entry, click on the Available Software tab and click on the Add Site button. This will open a dialog box where you insert the following URL:  http://pydev.org/updates/ . Then press OK and follow the instructions. This will result in the Pydev plug-in being automatically downloaded. Click on the install button to install it among your other Eclipse plug-ins. Furthermore it will automatically inform you in future when new updates are available. The Home page for Pydev is: http://pydev.org/ .&lt;br /&gt;
At this point you have all the software pre-requisites installed, ready for the next step.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Creating a new project ====&lt;br /&gt;
&lt;br /&gt;
When you first open the Eclipse platform after a new installation you will be asked to set-up a workspace, which will normally be in your home directory by default, then you will see  a Welcome screen with various buttons. Click on the one that opens the Eclipse workspace, which will be empty and probably be Java oriented.&lt;br /&gt;
To change it to be Python oriented you must open what in Eclipse is called a &amp;quot;perspective&amp;quot;, which is a combination of views and windows which suits the plug-in you are actually using at any one time. So, go to the Window &amp;amp;rarr; Open Perspective sub-menu and select Pydev. This will open the Pydev perspective where most of your development work will be done, and since new development starts with a new Project, now go to the File &amp;amp;rarr; New menu and select Pydev Project, and follow the prompts to create a new empty Python project which we will name Myproject. &lt;br /&gt;
&lt;br /&gt;
==== Configuring Eclipse and Pydev ====&lt;br /&gt;
&lt;br /&gt;
Eclipse is highly configurable, but for our purpose we will only look at the configuration required for Python use. &lt;br /&gt;
There are three preferences menus you should know,  the Window (or Eclipse) Preferences menu, the Project Properties menu, and the Run or Debug Configuration menu, but for our needs we will just look at Window and Run Configuration.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Open the Window &amp;amp;rarr; Preferences menu, expand the Pydev entry and select Interpreter - Python. Sometime Eclipse can automatically detect the location of your Python interpreter, in which case it will appear in the top right box: but if it didn't simply add it via the New button (remember you made a note of its location earlier on!).&lt;br /&gt;
In the bottom box add the following New Folders to the ones automatically added by Eclipse, and which point to the GRASS libraries (in Mac(?) they will be located within the GRASS installation directory tree):&lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
 /usr/lib/grass64/etc&lt;br /&gt;
 /usr/lib/grass64/etc/python&lt;br /&gt;
 /usr/lib/grass64/scripts&lt;br /&gt;
 /usr/lib/grass64/bin&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
 C:\GRASS-4-SVN\etc&lt;br /&gt;
 C:\GRASS-4-SVN\etc\python&lt;br /&gt;
 C:\GRASS-4-SVN\scripts&lt;br /&gt;
 C:\GRASS-4-SVN\bin &lt;br /&gt;
&lt;br /&gt;
then press Apply and OK. Finally go to the Run  Configurations menu and create a new entry for test.py as follows:&lt;br /&gt;
&lt;br /&gt;
* Click on Python Run, then click on the New configuration icon, the first at the top. Provide a Name, Project and Module names either manually or by browsing and press Apply to create the new configuration.&lt;br /&gt;
&lt;br /&gt;
* Click on the Environment tab and enter the following variables and values, keeping in mind that as shown they reflect my configuration.When you start GRASS it sets most of these variables but since you now want to run programs without GRASS itself running, you will have to set them yourself and find the equivalent locations for your specific configuration. If you have trouble do the following: in Windows or Linux (and Mac?) start GRASS  and in the GRASS command shell type 'export' without quotes or parameters. This will list all the variables and their values as they apply to your GRASS environment, but don't be scared by their number, just look up the few I have listed then adjust their values  accordingly: &lt;br /&gt;
&lt;br /&gt;
Linux:&lt;br /&gt;
 GISBASE=/usr/lib/grass64&lt;br /&gt;
 GISRC=/home/george/.grassrc6 		&lt;br /&gt;
 LD_LIBRARY_PATH=/usr/lib/grass64/lib 		&lt;br /&gt;
 PATH=/home/george/local/jdk1.6.0_13/lib:/home/george/local/jdk1.6.0_13/jre:/home/george/local/jdk1.6.0_13/jre/bin/java/home/george/local/jdk1.6.0_13/jre/bin:/usr/lib/grass64:/usr/lib/grass64/bin:/usr/lib/python2.6:/usr/lib/grass64/lib:usr/lib/grass64/scripts:/usr/lib/grass64/etc:/usr/lib/grass64/etc/python:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games  &lt;br /&gt;
 PYTHONPATH=/usr/lib/grass64/etc:/usr/lib/grass64/etc/python:/usr/lib/grass64/lib:/usr/lib/grass64/bin:/usr/lib/grass64/scripts:/usr/lib/python2.6&lt;br /&gt;
 PYTHONLIB=/usr/lib/python2.6&lt;br /&gt;
&lt;br /&gt;
Windows:&lt;br /&gt;
 GISBASE= C:\GRASS-4-SVN&lt;br /&gt;
 GISRC= C:\Documents and Settings\user\.grassrc6&lt;br /&gt;
 LD_LIBRARY_PATH= C:\GRASS-4-SVN\lib&lt;br /&gt;
 PATH= C:\GRASS-4-SVN\etc;C:\GRASS-4-SVN\etc\python;C:\GRASS-4-SVN\lib;C:\GRASS-4-SVN\bin;C:\GRASS-4-SVN\extralib;C:\GRASS-4-SVN\scripts;C:\Python26;&lt;br /&gt;
 PYTHONLIB= C:\Python26&lt;br /&gt;
 PYTHONPATH= C:\GRASS-4-SVN\etc;C:\GRASS-4-SVN\etc\python;C:\GRASS-4-SVN\lib;C:\GRASS-4-SVN\bin;C:\GRASS-4-SVN\extralib;C:\GRASS-4-SVN\scripts;C:\Python26;&lt;br /&gt;
&lt;br /&gt;
and Apply all of them.&lt;br /&gt;
* Now click on the Interpreter tab to verify that the interpreter has been correctly located and Pythonpath correctly set. Press OK to exit and now you are ready to run or debug your first Python program from Eclipse!&lt;br /&gt;
&lt;br /&gt;
==== Running a test program ====&lt;br /&gt;
&lt;br /&gt;
Finally create the following new Python source program by right-clicking the Myproject source tree and selecting New &amp;amp;rarr; File from the menu. Name the file test.py (including the extension) and when the empty file opens on your workspace paste the following lines:&lt;br /&gt;
&lt;br /&gt;
 import os&lt;br /&gt;
 import grass.script as grass&lt;br /&gt;
 env = grass.gisenv()&lt;br /&gt;
 print env&lt;br /&gt;
 #List all environment variables&lt;br /&gt;
 for key, value in os.environ.items(): print key, value &lt;br /&gt;
 #Print region extent&lt;br /&gt;
 r = grass.read_command(&amp;quot;g.region&amp;quot;, flags='p' )&lt;br /&gt;
 print r&lt;br /&gt;
&lt;br /&gt;
Save the file and press the Run button in the Run Configuration dialog, or from the Run menu select 'Run'.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Eclipse]] in general&lt;br /&gt;
&lt;br /&gt;
[[Category:Development]]&lt;br /&gt;
[[Category:FAQ]]&lt;/div&gt;</summary>
		<author><name>⚠️Sonja</name></author>
	</entry>
</feed>