I'm trying very hard to get spyder to run the grass module but have not succeeded.
I tried the grass documentation and these Q&As:
- Using Spyder IDE to develop python for Grass GIS, get 'ImportError: No module named grass.script' and
- How do I connect my Python script external to the Grass GIS 7 program in Windows 10?
This is my code:
import os
import sys
import subprocess
grass7bin = r'C:\OSGeo4W64\bin\grass72.bat'
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 = str(out.decode('utf-8'))
gisbase = gisbase.rstrip()
os.environ['GISBASE'] = gisbase
#set up GRASS environment variables
grass_pydir = os.path.join(gisbase, "etc", "python")
sys.path.append(grass_pydir)
import grass.script.setup as gsetup
I ran spyder with python 3 and grass 7.2.0.
-
Can you elaborate on "...but have not succeeded."? Any error message?markusN– markusN2017年07月22日 09:50:31 +00:00Commented Jul 22, 2017 at 9:50
-
The error message is the one in the subject line: No module named grass.scriptasher– asher2017年07月23日 06:11:13 +00:00Commented Jul 23, 2017 at 6:11
-
Did you ever get to solve that problem? I have the same problem in python 3, can't find a solutionOlivier– Olivier2018年06月20日 08:06:45 +00:00Commented Jun 20, 2018 at 8:06
lang-py