2

I am trying to use Python with Grass GIS. To get started I try to read in a raster TIFF.

The import of grass.script works fine:

import grass.script as g

But if I am trying to run a command I get the following error

sloperaster = 'slopet.tif'

a = g.run_command('r.in.gdal',
                      input = sloperaster,
                      output = 'test')

>>>'r.in.gdal' is not recognized as an internal or external command,
operable program or batch file.

Any ideas what is causing that and how to resolve it?

I am on Windows 7 (64bit), Python 2.7.5 (32bit), Grass GIS 6.4.3 (32bit)

1 Answer 1

5

There are three ways to use Python with GRASS GIS:

1) from the Python shell of the GRASS GIS Layer Manager:

enter image description here

  • you don't need to import any GRASS Python module

2) from the Python shell in the GRASS shell

enter image description here

  • you only need to import the grass.script module

3) from outside

enter image description here

For that,

  • some environment variables have to be set before using Python, see "Creating Python scripts that call GRASS functionality from outside" in GRASS and Python
  • some GRASS variables have to be set in Python (GISBASE, gisdb, location, mapset)
1
  • I use option 3. I did set the environment variables. Also I think in the right way otherwise I wouldn't be able to import grass.script. But I didn't set any GRASS variables. Maybe that's why it doesn't work. I look into that. Thanks. Commented Oct 10, 2013 at 16:43

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.