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

Vaclav Petras wenzeslaus at gmail.com
Thu Aug 4 17:37:05 PDT 2016


Hi,

On Thu, Aug 4, 2016 at 7:50 PM, Jose M <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 GISBASEstartcmd = [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/20160804/55c0d871/attachment.html>


More information about the grass-user mailing list