[GRASS-windows] Re: [GRASS-user] Problem with running Python script in GRASS

Glynn Clements glynn at gclements.plus.com
Fri May 7 07:51:15 EDT 2010


Luigi Ponti wrote:

> > Windows, Python and 6.4 isn't the most reliable combination.
> >
> > At a minimum, you need a fairly recent version of 6.5 to be able to
> > use Python scripts on Windows (the hacks required to get shell scripts
> > to work on Windows get in the way of running other scripts). 6.4.0-RC6
> > won't work (g.parser was updated, but lib/python wasn't).
> 
> Is this true also for the daily WinGRASS-6.4.SVN at 
> http://josef.fsv.cvut.cz/wingrass/ and will this hold true for 6.4 in 
> general?

The current 6.4 SVN head has been updated to use "g.parser -s", which
eliminates the main issue with Python scripts (on Windows, you can't
"execute" a script based upon the "#!" line, so g.parser explicitly
invoked the script via %GRASS_SH%, which didn't work for Python
scripts).

> > You also need a "clean" Python install with the correct registry
> > entries, 
> 
>  From what you say, one needs two Python installations: the one that 
> comes with GRASS and an additional "fresh" one -- is it ok to install 
> the current Python 2.6.5 version or 2.5 is better (2.6 seems to be ok 
> from http://grass.osgeo.org/wiki/GRASS_and_Python)? From the 
> GRASS/Python wiki one also infers that on Windows the Python binaries 
> that come with the GRASS installation are no longer used (?).

You don't need the version which comes with GRASS, and you're probably
better off not using it. You need Python 2.4 or later, with wxWidgets
2.8, NumPy, and PyWin32.

[The main reason for the attempt at "bundling" Python in the installer
is to eliminate the need to install wxWidgets, NumPy and PyWin32 to
match the installed version of Python.]

You may need to set PYTHONPATH to %WINGISBASE%\etc\python in order for
scripts to find the grass.script module. You may also need to add
%WINGISBASE%\scripts to %PATH% (Init.bat doesn't do this on Windows,
as shell scripts in the scripts directory are invoked via a matching
batch file in the bin directory).

> (Currently I am using WinGRASS-6.4.SVN-r42046-1 from the installer 
> downloaded at the link above; OS is windows 7.)
> 
> > and you may need to hack the GRASS startup scripts (the
> > WinGRASS installer fails quite badly with regard to Python, and the
> > OSGeo4W installer fails even harder).
> >   
> 
> But my question is actually: if a user wants to take a (Windows) Python 
> scripting approach to GRASS, what version should she/he target? My 
> impression is that trying to build functionality using GRASS 7 may have 
> the best returns, although I am not sure how feasible is that right now, 
> i.e. what GRASS 6 functionality can currently be ported to GRASS 6 (I am 
> thinking for example to a way around the display issue that in 6.4 is 
> solved using appropriate settings for e.g. GRASS_RENDER_IMMEDIATE).

A lot of the fundamental issues have been fixed in 7.0, although it
isn't as widely deployed and hasn't been as widely tested as 6.x.

The need for backwards compatibility in 6.x makes it harder to deal
with some fundamental portability issues, while 7.0 doesn't have that
problem (if existing mechanisms aren't portable, they get replaced
with something that is, even if it breaks compatibility).

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


More information about the grass-user mailing list