[GRASS-dev] Fwd: [GRASS-user] How to embed a grass script (for example v.db.addcol) into a Pythonscript on windows?

Glynn Clements glynn at gclements.plus.com
Fri Apr 2 18:54:22 EDT 2010


Michael Barton wrote:

> OK. This helps. We were trying it in the "MSys' (broken and deprecated)
> rxvt program".
> 
> Like I said, I'm not familiar enough with Windows to realize that this
> would not work. I'm trying to help get python GRASS scripts to work
> under Windows. So testing it from MSys is not the way to go. Should we
> just try running a python script from the wxpython command prompt? Or
> should we do it from the MSys prompt?

First, I would suggest using the batch file which I posted (or
something quite similar) to start a session using cmd.exe in a Windows
console.

For running a *script*, it shouldn't matter whether you use rxvt or a
console, but it will matter for running Python interactively. Using
bash might cause problems, so it's best to avoid that at first.

> Is there a shebang that we should be using on Windows that is different
> from the stock one (#!/usr/bin/env python). 

Shebangs don't work with Windows; that's a feature of MSys' bash.
Windows uses the extension.

If you've installed Python using the stock .msi installer from
python.org, it should have associated the .py extension with the
python.file type, and the python.file type with something like:

	"C:\Python26\python.exe" "%1" %*

> I'm looking for a cookbook approach that I can tell to students and
> other who would like to use GRASS on Windows. I understand that there
> are difficulties with this, but am trying to find way to make scripting
> useable for people who cannot compile on Windows, but can modify batch
> and other scripts. So far, we've 
> 
> 1) installed Python from the python site
> 2) installed the GRASS binary (not the OSGeo4Win version, but the
> standalone native Windows one)
> 3) replaced the startup batch file with the commands you provided
> 
> Do we need to do something else? Do we need to start a script in a
> special way (e.g., by exec-ing python first? Do we need batch files to
> launch python scripts like we do for bash scripts?

1. The Python scripts need to have a .py extension.
2. You may need:

	set PYTHONPATH=%WINGISBASE%\etc\python

as grass65.bat (etc) only sets this when invoked with -wxpython.

> In a related question, maybe more for Colin, does GRASS 7 work in
> Windows? If so, what is the setup to allow it to run the scripts in
> Python?

GRASS 7 works in Windows using a similar batch file to that which I
posted for 6.x. However, the Init.bat file needs some work. Starting
with -wxpython doesn't work (you can start it manually via g.gui,
though). If you start in -text mode, you'll get a couple of errors
about the missing set_data program, but you'll end up in a session
using the existing .grassrc7 file (provided that one exists).

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


More information about the grass-dev mailing list