I'm getting crazy with grass gis and python. I want to call a grass function from an external python script (using spyder for instance).

I've installed QGIS + GRASS with the OSGeo4W64 installation suite (Desktop Express installation mode).

My code is the following:

I've specivied which line is working and which is not in the code:

import os
import sys

GISBASE = os.environ['GISBASE'] = 'C:\\OSGeo4W64\\apps\\grass\\grass-7.2.2' 
#GRASS_PYTHON = os.environ['GRASS_PYTHON'] = os.path.join(GISBASE,'extrabin','python.exe')
#PYTHONHOME = os.environ['PYTHONHOME'] = os.path.join(GISBASE,'Python27')
#GRASS_PROJSHARE = os.environ['GRASS_PROJSHARE'] = os.path.join(GISBASE,'share','proj')

#os.environ['PATH']+=os.pathsep +os.path.join(GISBASE,'extrabin')
os.environ['PATH']+=os.pathsep +os.path.join(GISBASE,'bin')
os.environ['PATH']+=os.pathsep +os.path.join(GISBASE,'lib')
LD_LIBRARY_PATH= os.environ['LD_LIBRARY_PATH'] = os.path.join(GISBASE,'lib')

os.environ['PATH']+=os.pathsep +"C:\\OSGeo4W64\\bin"

gisdb = os.path.join(os.path.expanduser("~"), "grassdata")

location = "lacLeman"
mapset = "PERMANENT"

grass_pydir = os.path.join(GISBASE, "etc", "python")

import grass.script as gscript
import grass.script.setup as gsetup
#this line works
rcfile = gsetup.init(GISBASE, gisdb, location, mapset)

## this line works
## this line doesn't (that's what I want ultimately to do)
#gscript.run_command('r.horizon', elevation='elevation',step=1,coordinate=(512102.844311,148320.733533))
## this line doesn't work 
gscript.read_command('g.region', flags='p')

My Output Errors:

I got two successive windows error (see screenshot below):

Entry point error for spatialite.dll

Entry point error for gdal202.dll

Additionally I code an error in my Ipython shell:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 45: ordinal not in range(128)

But I think this error is just due to the errors mentioned above.

What did I miss?

I'm running on windows 10.

  • Check that the bitness of your libraries are matching; that Python, GRASS and QGIS all are 64-bit or 32-bit. GRASS cannot find the function name in the library it is accessing. 32/64 bit programs usually cannot see the address of a function in another non-compatible library even though the library can be seen.
    – RomaH
    Jan 23, 2018 at 17:00
  • In addition, please consider to use GRASS GIS 7.4 available from the "Advanced" tab in OSGeo4W. It will soon be released, hence it then also shows up in the "Express" installation - here just FYI since you report troubles with the older 7.2 version.
    – markusN
    Jan 24, 2018 at 6:48

1 Answer 1


You can find the description of the error caused by sqlite3.dll here: WinGRASS errors.

Having tried renaming all sqlite3.dll files, at least this error is temporarily fixed.

However, the error due to spatialite.dll still remains an issue.

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.