[GRASS-user] Problems with GRASS python code in osgeo4w

Glynn Clements glynn at gclements.plus.com
Fri Jun 19 22:03:26 EDT 2009


Moskovitz, Bob wrote:

> I'm trying to figure out how to write python scripts using grass.py
> under osgeo4w.  I was hoping that python script (and the binary
> commands) would behave similarly to the grass environment on my Ubuntu
> box.  You know...just type the command and the gui for that command
> comes up.  What I have to do now is type "python
> c:\osgeo4w\apps\grass\grass-6.4.0svn\scripts\m.dipslope.py" instead of
> just type "m.dipslope.py".  I've also notice that the command gui or
> even the command help does not come up when you just enter the command.
> Ultimately I would like to put my commands in the QGIS GRASS module
> tree.

1. Ensure that .py files are configured to be run with the Python
interpreter. You should be able to double-click on a .py file in
Explorer and have it run. This should be done by the Python installer,
but I don't know if the OSGeo4W installer does this.

If it isn't, you can use e.g.:

  assoc .py=python.file
  ftype python.file="C:\Program Files\Python25\python.exe" "%1"

[Change the pathname to wherever Python is installed.]

2. The PATHEXT environment variable needs to contain ".PY" if you want
to use "m.dispslope" rather than "m.dispslope.py". You can do this
temporarily with:

  set PATHEXT=%PATHEXT%;.PY

or you can make it persistent either using the Control Panel or
through the registry.

For the Control Panel in XP, it's:

My Computer
 Control Panel
  System
   Advanced (Tab)
    Environment Variables

For the registry, the system-wide setting is taken from the PATHEXT
value of the key:

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Or you can override it for the current user by adding a PATHEXT value
to the key HKCU\Environment

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


More information about the grass-user mailing list