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")
sys.path.append(grass_pydir)
import grass.script as gscript
import grass.script.setup as gsetup
#this line works
rcfile = gsetup.init(GISBASE, gisdb, location, mapset)
## this line works
print(gscript.read_command('r.info',map='elevation',flags='g'))
## 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):
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.