[GRASS-user] Error trying to run grass from python script/command line in Windows

Jose M soloninguno at hotmail.com
Thu Aug 4 18:29:12 PDT 2016


Hi Vaclav,


Thanks for your suggestions


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

C:\OSGeo4W\apps\grass\grass-7.0.4 folder, the bat seems to be only created using the standalone grass installers).

Using this way I'm getting the same stacktrace.
script.run_command('g.list', flags='m', type='raster')

Running the os.environ shows me several variables, the more relevants I suppose are
'PYTHONPATH': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4\\etc\\python'
'GISBASE': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4'
'GISRC': 'c:\\users\\Carl\\appdata\\local\\temp\\tmprv4iwf'
'GIS_LOCK': '5156'
'GRASS_PYTHON': 'python.exe'
'GRASS_ADDON_BASE': 'C:\\Users\\Carl\\AppData\\Roaming\\GRASS7\\addons'
'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',
'GDAL_DRIVER_PATH': 'C:\\Program Files (x86)\\GDAL\\gdalplugins'
'GDAL_DATA': 'C:\\Program Files (x86)\\GDAL\\gdal-data'
'SAGA_MLB': 'C:\\Saga\\modules'
'GISBASE': 'C:\\OSGeo4W\\apps\\grass\\grass-7.0.4'
'GDAL_HOME': 'C:\\Program Files (x86)\\GDAL'
'PYTHON_HOME': 'C:\\Python27'
'SAGA_HOME': 'C:\\Saga'

I forgot to mention in the first mail that before getting the stack trace a popup appear saying this

===
Microsoft Visual C++ Runtime Library

Program
C:\OSGeo4W\apps\grass\grass-7.0.4\bin\g.gisenv.EXE

R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
===

And then another popup with a g.gisenv.exe application error printing the error 0x0000142.


What i discover is that if I remove gdal from PATH environment, the error change to "iconv.dll missing" but with a similar stacktrace

===
grass.exceptions.CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error
Process ended with non-zero return code -1073741515. See errors in the (error) output.
===



Maybe has something to do that my OS is Win 7 x64 ? I choose the x32 as my system wide python is x32.

Thanks!

________________________________
De: Vaclav Petras <wenzeslaus at gmail.com>
Enviado: jueves, 04 de agosto de 2016 09:37 p.m.
Para: Jose M
Cc: grass-user at lists.osgeo.org
Asunto: Re: [GRASS-user] Error trying to run grass from python script/command line in Windows

Hi,

On Thu, Aug 4, 2016 at 7:50 PM, Jose M <soloninguno at hotmail.com<mailto:soloninguno at hotmail.com>> wrote:
gisbase = r'C:\OSGeo4W\apps\grass\grass-7.0.4'
os.environ['GISBASE'] = gisbase


likely unrelated but I suggest to use the way specified in the manual, i.e. obtaining the GISBASE value from the binary:


# 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)

https://grass.osgeo.org/grass72/manuals/libpython/script.html#module-script.setup



gscript.run_command('g.list -m type=raster')

Unrelated, but this is not guaranteed to work. Use the syntax:

gscript.run_command('g.list', flags='m', type='raster')



And this is the stacktrace I'm getting
C:\test>setupgrass.py
Traceback (most recent call last):
  File "C:\test\setupgrass.py", line 20, in <module>
    gscript.run_command('g.list -m type=raster')
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 393, in run_command
    ps = start_command(*args, **kwargs)
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 356, in start_command
    if debug_level() > 0:
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 1519, in debug_level
    _debug_level = int(gisenv().get('DEBUG', 0))
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 935, in gisenv
    s = read_command("g.gisenv", flags='n')
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 446, in read_command
    return handle_errors(returncode, stdout, args, kwargs)
  File "C:\OSGeo4W\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 313, in handle_errors
    returncode=returncode)
grass.exceptions.CalledModuleError: Module run None ['g.gisenv', '-n'] ended with error
Process ended with non-zero return code -1073741502. See errors in the (error) output.


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

print os.environ

after init() call to see how the paths are set.

Vaclav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20160805/62a3763e/attachment-0001.html>


More information about the grass-user mailing list