<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Hi,</p>
<p><br>
</p>
<p>I'm new to grass and I'm having an issue trying to run grass from a python script in my Windows 7 x64 environment.</p>
<p>I've read this links<br>
</p>
<p><a id="LPlnk959561" href="https://grasswiki.osgeo.org/wiki/GRASS_and_Python#MS-Windows" class="OWAAutoLink">https://grasswiki.osgeo.org/wiki/GRASS_and_Python#MS-Windows</a></p>
<p><a id="LPlnk205073" href="https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly" class="OWAAutoLink">https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly</a></p>
<p><a id="LPlnk527932" href="https://grass.osgeo.org/grass70/manuals/libpython/script.html#module-script.setup" class="OWAAutoLink">https://grass.osgeo.org/grass70/manuals/libpython/script.html#module-script.setup</a></p>
<p><br>
</p>
<p>But I'm not getting this working.</p>
<p><br>
</p>
<p>Here is my python script, running a simple g.list command<br>
</p>
<p></p>
<div><br>
===<br>
import os<br>
import sys<br>
import subprocess<br>
<br>
gisbase = r'C:\OSGeo4W\apps\grass\grass-7.0.4'<br>
os.environ['GISBASE'] = gisbase<br>
grass_pydir = os.path.join(gisbase, "etc", "python")<br>
sys.path.append(grass_pydir)<br>
<br>
import grass.script as gscript<br>
import grass.script.setup as gsetup<br>
<br>
gisdb = os.path.join(os.path.expanduser("~"), "Documents/grassdata")<br>
location = "nc_spm_08"<br>
mapset = "user1"<br>
<br>
rcfile = gsetup.init(gisbase, gisdb, location, mapset)<br>
<br>
# use grass functions here<br>
gscript.run_command('g.list -m type=raster')<br>
<br>
os.remove(rcfile)<br>
===<br>
<br>
And this is the stacktrace I'm getting<br>
C:\test>setupgrass.py<br>
Traceback (most recent call last):<br>
  File "C:\test\setupgrass.py", line 20, in <module><br>
    gscript.run_command('g.list -m type=raster')<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 393, in run_command<br>
    ps = start_command(*args, **kwargs)<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 356, in start_command<br>
    if debug_level() > 0:<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 1519, in debug_level<br>
    _debug_level = int(gisenv().get('DEBUG', 0))<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 935, in gisenv<br>
    s = read_command("g.gisenv", flags='n')<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 446, in read_command<br>
    return handle_errors(returncode, stdout, args, kwargs)<br>
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 313, in handle_errors<br>
    returncode=returncode)<br>
grass.exceptions.CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error<br>
Process ended with non-zero return code -1073741502. See errors in the (error) output.</div>
<p></p>
<p><br>
</p>
<p>I tried both with Grass standalone installer, and <span>with grass installed through OSGeo4W</span> spackages and I'm getting the same error.</p>
<p><br>
</p>
<p>Anyone knows what the problem could be? </p>
<p><br>
</p>
<p>Thanks in advance!<br>
</p>
</div>
</body>
</html>