I've been trying to set up a python script so I can run grass functions by running the script from my command window. The setting up seems to be working, but now I get a system error (different window) saying that the program can't be started because gdal200.dll is missing from my computer. It suggests to possibly solve the problem by re installing the program. (Dutch exact message: Het programma kan niet worden gestart omdat gdal200.dll ontbreekt op uw computer. U kunt dit probleem mogleijk oplossen door het programma opnieuw te installeren).

Consequently the error message in the prompt window is:

*Traceback (most recent call last):
  File "probeertry.py", line 65, in <module>
    for rast in g.list_strings(type = 'rast'):
  File "C:\OSGEO4~1\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 1143, in list_strings
  File "C:\OSGEO4~1\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:\OSGEO4~1\apps\grass\grass-7.0.4\etc\python\grass\script\core.py", line 313, in handle_errors
grass.exceptions.CalledModuleError: Module run None ['g.list', '--q', '-m', 'type=rast'] ended with error
Process ended with non-zero return code -1073741515. See errors in the (error) output.*

If I search for the gdal200.dll on my computer it is actually present in two different places (which might make the error, but then, can I delete one?!) It's found in C:\OSGeo4W64\bin as well as in C:\Program Files\QGIS 2.14\bin. If I run the same script (found below) directly from the python console, this problem doesn't occur. (I do have a different problem with importing my self made modules there, which doesn't occur if using command prompt... If you have any suggestions on this, would be welcome as well :)) So it's not actually the script but the system.. Can anyone help me with this one?

Here's my script. It goes wrong once using the grass commands (line g.message)

# settings
import os
import sys
import subprocess

grass7bin_win = r'C:\OSGeo4W64\bin\grass70.bat'
gisdb = r"C:\GrassData\2016MDP"

# QGISinst=u'C:/PROGRA~1/QGIS2~1.14/apps/qgis-ltr'
# qgs = QgsApplication([], False)
# qgs.initQgis()

if sys.platform.startswith('win'):
    grass7bin = grass7bin_win
    print "platform should be configured now"
    raise OSError('Platform not configured.')

print grass7bin

# query GRASS GIS itself for its GISBASE
startcmd = [grass7bin, '--config', 'path']
    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)

# set GISBASE environment variable
os.environ['GISBASE'] = gisbase

# define GRASS-Python environment
grass_pydir = os.path.join(gisbase, "etc", "python")
sys.path.append(r"C:\Program Files\QGIS 2.14\bin")

# import (some) GRASS Python bindings
import grass.script as g
import grass.script.setup as gsetup

gsetup.init(gisbase, gisdb, location, mapset)

print gisbase
##check Path
print sys.path

g.message('Current GRASS GIS 7 environment:')
print g.gisenv()

g.message('Available raster maps:')
for rast in g.list_strings(type = 'rast'):
    print rast

Let me know what you think! Or if I should look somewhere else/provide more info.

OS: Windows 10 64bit QGIS: Desktop 2.14.6 with Grass 7.0.4 Python27


I've been having the same problem and the same error code lately while trying to create the location via python script. It seems related to the way Windows look for dll's. To possibly solve it you have to add the 'lib' directory path to the 'PATH' environment variable via os.environ command. So, in your case it would look something like:

os.environ['PATH'] += ';' + r"C:\OSGEO4~1\apps\grass\grass-7.0.4\lib"
  • This doesn't seem to help. It shouldn't matter where I put it right? – Vera Knook Oct 6 '16 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.