Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error Process ended with non-zer return code -1073741701. See errors in the (error) output.
- import os, sys, subprocess
- # define GRASS database, location and mapset
- gisdb = r'C:datagrass'
- location = "Country"
- mapset = "Solar"
- # location of GRASS start script
- grass7bin = r'C:Program FilesQGIS2.18bingrass72.bat'
- # query GRASS GIS itself for its GISBASE
- startcmd = [grass7bin, '--config', 'path']
- try:
- p = subprocess.Popen(startcmd, shell=False,
- stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- out, err = p.communicate()
- except OSError as error:
- sys.exit("ERROR: Cannot find GRASS GIS start script"
- " {cmd}: {error}".format(cmd=startcmd[0], error=error))
- if p.returncode != 0:
- sys.exit("ERROR: Issues running GRASS GIS start script"
- " {cmd}: {error}"
- .format(cmd=' '.join(startcmd), error=err))
- gisbase = out.strip(os.linesep)
- # set GISBASE environment variable
- os.environ['GISBASE'] = gisbase
- os.environ['GISDBASE'] = gisdb
- # define GRASS-Python environment
- grass_pydir = os.path.join(gisbase, "etc", "python")
- sys.path.append(grass_pydir)
- # import GRASS Python bindings
- import grass.script as gscript
- import grass.script.setup as gsetup
- # launch session
- rcfile = gsetup.init(gisbase, gisdb, location, mapset)
- # example calls
- gscript.message('Current GRASS GIS 7 environment:')
- print gscript.gisenv()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement