1

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:

  1. Using Spyder IDE to develop python for Grass GIS, get 'ImportError: No module named grass.script' and
  2. 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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 19, 2017 at 6:40
3
  • Can you elaborate on "...but have not succeeded."? Any error message? Commented Jul 22, 2017 at 9:50
  • The error message is the one in the subject line: No module named grass.script Commented 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 solution Commented Jun 20, 2018 at 8:06

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.