2

I am trying to run Python code for Grass GIS from this site

Specifically, here is my code:

## Import libraries needed to call GRASS using Python
import grass.script as grass
from grass.script import core as grass
import grass.script as grass 
grass.run_command('g.region', raster='elevation')

But I am getting the following error:

---------------------------------------------------------------------------
CalledModuleError                         Traceback (most recent call last)
<ipython-input-13-2ea69f70ebcb> in <module>()
      7 from grass.script import core as grass
      8 import grass.script as grass
----> 9 grass.run_command('g.region', raster='elevation')

C:\Program Files\GRASS GIS 7.5.svn\etc\python\grass\script\core.pyc in run_command(*args, **kwargs)
    419     else:
    420         returncode = ps.wait()
--> 421     return handle_errors(returncode, returncode, args, kwargs)
    422 
    423 

C:\Program Files\GRASS GIS 7.5.svn\etc\python\grass\script\core.pyc in handle_errors(returncode, result, args, kwargs)
    330         args = make_command(*args, **kwargs)
    331         raise CalledModuleError(module=None, code=repr(args),
--> 332                                 returncode=returncode)
    333 
    334 def start_command(prog, flags=b"", overwrite=False, quiet=False,

CalledModuleError: Module run None ['g.region', 'raster=elevation'] ended with error
Process ended with non-zero return code 1. See errors in the (error) output.
  • what happens if you run the last two lines? (skipping the third) – Elio Diaz Dec 8 '17 at 22:28
1

I tried your code, and I get the same result, you have to do the def,

import grass.script as gscript



def main():
    gscript.run_command('g.region', flags='p')


if __name__ == '__main__':
    main()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.