<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 Vaclav,</p>
<p><br>
</p>
<p>Thanks for your suggestions</p>
<p><br>
</p>
<p>I already tried obtaining the gisbase from the binary but got the same error, so i then switch to the shorthand way (besides, instaling grass through the Osgeo4w doesn't create a grass70.bat in the </p>
<div>C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4 folder, the bat seems to be only created using the standalone grass installers).<br>
<br>
Using this way I'm getting the same stacktrace.<br>
<span>script.run_command('g.list', flags='m', type='raster')</span><br>
<br>
Running the os.environ shows me several variables, the more relevants I suppose are<br>
<span>'PYTHONPATH': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\etc\\python'</span><br>
<span>'GISBASE': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4'</span><br>
<div><span></span>'GISRC': 'c:\\users\\Carl\\appdata\\local\\temp\\tmprv4iwf'<br>
<div>'GIS_LOCK': '5156'<br>
<span>'GRASS_PYTHON': 'python.exe'</span><br>
</div>
'GRASS_ADDON_BASE': 'C:\\Users\\Carl\\AppData\\Roaming\\GRASS7\\addons'<br>
<div>'PATH': ''C:\\Windows\\SYSTEM32;C:\\Windows;C:\\Windows\\SYSTEM32\\WBEM;C:\\Program Files (x86)\\GDAL;C:\\Python27;C:\\Python27;C:\\Python27\\Scripts;C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\bin;C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\scripts;C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\extrabin;C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\lib',<br>
<div>'GDAL_DRIVER_PATH': 'C:\\Program Files (x86)\\GDAL\\gdalplugins'<br>
'GDAL_DATA': 'C:\\Program Files (x86)\\GDAL\\gdal-data'<br>
'SAGA_MLB': 'C:\\Saga\\modules'<br>
'GISBASE': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4'<br>
'GDAL_HOME': 'C:\\Program Files (x86)\\GDAL'<br>
'PYTHON_HOME': 'C:\\Python27'<br>
'SAGA_HOME': 'C:\\Saga'<br>
</div>
<br>
I forgot to mention in the first mail that before getting the stack trace a popup appear saying this<br>
<br>
===<br>
Microsoft Visual C++ Runtime Library<br>
<br>
Program<br>
C:\OSGeo4W\apps\grass\grass-7.0.4\bin\g.gisenv.EXE<br>
<br>
R6034<br>
An application has made an attempt to load the C runtime library incorrectly.<br>
Please contact the application's support team for more information.<br>
===<br>
<br>
And then another popup with a g.gisenv.exe application error printing the error 0x0000142.</div>
</div>
<br>
<br>
<div>What i discover is that if I remove gdal from PATH environment, the error change to "iconv.dll missing" but with a similar stacktrace<br>
<div><br>
===<br>
grass.exceptions.CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error<br>
Process ended with non-zero return code -1073741515. See errors in the (error) output.</div>
===<br>
<br>
<br>
</div>
<br>
Maybe has something to do that my OS is Win 7 x64 ? I choose the x32 as my system wide python is x32.<br>
</div>
<p></p>
<br>
Thanks!<br>
<br>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>De:</b> Vaclav Petras <wenzeslaus@gmail.com><br>
<b>Enviado:</b> jueves, 04 de agosto de 2016 09:37 p.m.<br>
<b>Para:</b> Jose M<br>
<b>Cc:</b> grass-user@lists.osgeo.org<br>
<b>Asunto:</b> Re: [GRASS-user] Error trying to run grass from python script/command line in Windows</font>
<div> </div>
</div>
<div>
<div dir="ltr">
<div class="gmail_extra">Hi,<br>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Aug 4, 2016 at 7:50 PM, Jose M <span dir="ltr"><<a href="mailto:soloninguno@hotmail.com" target="_blank">soloninguno@hotmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div>gisbase = r'C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4'<br>
os.environ['GISBASE'] = gisbase<br>
 </div>
</blockquote>
<div><br>
</div>
<div>likely unrelated but I suggest to use the way specified in the manual, i.e. obtaining the GISBASE value from the binary:<br>
<br>
<pre><span class=""># query GRASS GIS itself for its GISBASE</span>
<span class="">startcmd</span> <span class="">=</span> <span class="">[</span><span class="">grass7bin</span><span class="">,</span> <span class="">'--config'</span><span class="">,</span> <span class="">'path'</span><span class="">]</span>
<span class="">try</span><span class="">:</span>
    <span class="">p</span> <span class="">=</span> <span class="">subprocess</span><span class="">.</span><span class="">Popen</span><span class="">(</span><span class="">startcmd</span><span class="">,</span> <span class="">shell</span><span class="">=</span><span class="">False</span><span class="">,</span>
                         <span class="">stdout</span><span class="">=</span><span class="">subprocess</span><span class="">.</span><span class="">PIPE</span><span class="">,</span> <span class="">stderr</span><span class="">=</span><span class="">subprocess</span><span class="">.</span><span class="">PIPE</span><span class="">)</span>
    <span class="">out</span><span class="">,</span> <span class="">err</span> <span class="">=</span> <span class="">p</span><span class="">.</span><span class="">communicate</span><span class="">()</span>
<span class="">except</span> <span class="">OSError</span> <span class="">as</span> <span class="">error</span><span class="">:</span>
    <span class="">sys</span><span class="">.</span><span class="">exit</span><span class="">(</span><span class="">"ERROR: Cannot find GRASS GIS start script"</span>
             <span class="">" {cmd}: {error}"</span><span class="">.</span><span class="">format</span><span class="">(</span><span class="">cmd</span><span class="">=</span><span class="">startcmd</span><span class="">[</span><span class="">0</span><span class="">],</span> <span class="">error</span><span class="">=</span><span class="">error</span><span class="">))</span>
<span class="">if</span> <span class="">p</span><span class="">.</span><span class="">returncode</span> <span class="">!=</span> <span class="">0</span><span class="">:</span>
    <span class="">sys</span><span class="">.</span><span class="">exit</span><span class="">(</span><span class="">"ERROR: Issues running GRASS GIS start script"</span>
             <span class="">" {cmd}: {error}"</span>
             <span class="">.</span><span class="">format</span><span class="">(</span><span class="">cmd</span><span class="">=</span><span class="">' '</span><span class="">.</span><span class="">join</span><span class="">(</span><span class="">startcmd</span><span class="">),</span> <span class="">error</span><span class="">=</span><span class="">err</span><span class="">))</span>
<span class="">gisbase</span> <span class="">=</span> <span class="">out</span><span class="">.</span><span class="">strip</span><span class="">(</span><span class="">os</span><span class="">.</span><span class="">linesep</span><span class="">)</span></pre>
<br>
<a href="https://grass.osgeo.org/grass72/manuals/libpython/script.html#module-script.setup">https://grass.osgeo.org/grass72/manuals/libpython/script.html#module-script.setup</a><br>
<br>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div><br>
gscript.run_command('g.list -m type=raster')<br>
</div>
</blockquote>
<div><br>
</div>
<div>Unrelated, but this is not guaranteed to work. Use the syntax:<br>
<br>
gscript.run_command('g.list', flags='m', type='raster')<br>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div><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-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 393, in run_command<br>
    ps = start_command(*args, **kwargs)<br>
  File "C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 356, in start_command<br>
    if debug_level() > 0:<br>
  File "C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 1519, in debug_level<br>
    _debug_level = int(gisenv().get('DEBUG', 0))<br>
  File "C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 935, in gisenv<br>
    s = read_command("g.gisenv", flags='n')<br>
  File "C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 446, in read_command<br>
    return handle_errors(returncode, stdout, args, kwargs)<br>
  File "C:\OSGeo4W\apps\grass\grass-<wbr>7.0.4\etc\python\grass\script\<wbr>core.py", line 313, in handle_errors<br>
    returncode=returncode)<br>
grass.exceptions.<wbr>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>
</blockquote>
<div><br>
<p>According to my Internet search, -1073741502 means STATUS_DLL_INIT_FAILED - DLL Initialization Failed. So perhaps the installation is somehow broken or the paths are not set right. You can try</p>
<p>print os.environ</p>
<p>after init() call to see how the paths are set.</p>
<p>Vaclav<br>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>