Using the tutorials posted here, here and here, I am trying to setup a script that will make use of several GRASS GIS raster functions externally. For now I am just trying to get the tutorial script to run but I receive the following error:
CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error Process ended with non-zero return code -1073741515. See errors in the (error) output.
When searching for this error it seems that others have issues trying to import grass.script. However, I am able to import this without issue. It is only afterwards when trying to run a module that I get this error. This happens when I try to use a 'gscript.run_command('g.gisenv') (see code block below).
I run: - Windows 10 x64 - Python 2.7.13 x86 - GRASS GIS 7.2.0 x86 - x86 version of GDAL
I removed all other GRASS GIS installations (one was installed with QGIS) and reinstalled it with the required Microsoft Visual C++ Redistributable Packages.
import os
import sys
import subprocess
grass7bin = r'C:\Program Files (x86)\GRASS GIS 7.2.0\grass72.bat'
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)
os.environ['GISBASE'] = gisbase
grass_pydir = os.path.join(gisbase, "etc", "python")
sys.path.append(grass_pydir)
import grass.script.setup as gsetup
gisdb = r'C:\data\grass'
location = "Country"
mapset = "Topic"
rcfile = gsetup.init(gisbase, gisdb, location, mapset)
import grass.script as gscript
print'grass.script imported'
gscript.run_command('g.gisenv', 'n')
os.remove(rcfile)
EDIT:
After trying to reinstall GRASS GIS several times I decided to download a new GRASS GIS installation file and install that. Now the script runs without throwing the error.
EDIT 2:
I thought the issue was resolved but that is not the case. When I try to use a command as per the tutorial here:
gscript.run_command('r.in.gdal', input = inputVRT, output = outputName, overwrite = True)
It doesn't work and I again get a CalledModuleError:
Traceback (most recent call last):
File "C:\scripts\10_1_grassGis.py", line 54, in <module>
overwrite = True)
File "C:\Program Files (x86)\GRASS GIS 7.2.0\etc\python\grass\script\core.py", line 410, in run_command
return handle_errors(returncode, returncode, args, kwargs)
File "C:\Program Files (x86)\GRASS GIS 7.2.0\etc\python\grass\script\core.py", line 329, in handle_errors
returncode=returncode)
CalledModuleError: Module run None ['r.in.gdal', '--o', '--q', '-o', 'input=C:\\data\\rasters\\bykerneNet_03743.vrt', 'output=bykerne03743'] ended with error
Process ended with non-zero return code -1073741512. See errors in the (error) output.
However, if I try things like:
gscript.gisenv()
It runs fine.
What could be the issue?