Trying to run r.random using the script but receiving an error message. It works when the module is run outside of the python shell so it must be te code, I'm new to this so I can't figure out what is wrong.


grass.run_command("r.random", overwrite=True, input="island",npoints=15, raster="randomsample", vector="randomsample")


Process ended with non-zero return code 1. See errors in the (error) output.

  • The error is the same if I make them different, plus the module works with the same names if run outside of the python shell. – grassgis1234 May 14 '20 at 12:02

Did you import the respective GRASS GIS Python scripting API?

Using the "North Carolina sample dataset", it works like this:

>>> import grass.script as grass
>>> grass.run_command("r.random", overwrite=True, input="basin_50K",npoints=15, raster="randomsample", vector="randomsample")
Collecting Stats...
WARNING: Vector map <randomsample> already exists and will be overwritten
Writing raster map <randomsample> and vector map <randomsample> ...
Building topology for vector map <randomsample@user1>...
Registering primitives...

You can find examples here (and of course in the GRASS GIS source code as well):


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.