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)

asked Oct 10, 2013 at 0:06

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)
answered Oct 10, 2013 at 9:32
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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.