Hi I compiled Grass 7.0 (with OpenMP) on a CENTOS 7 OS.
everything works properly, but I’m not able to use PYGRASS
here is my first part of the codes if I add import pygrass I have the error:
import pygrass
ImportError: No module named pygrass
#!/usr/bin/env python
import os
import sys
import subprocess
import datetime, time
now = datetime.datetime.now()
StartTime = time.clock()
########### ########### ########### ########### ########### ########### ########### ########### ###########
########### ########### ########### ########### ########### ########### ########### ########### ###########
path to the GRASS GIS launch script
Linux
grass7bin_lin = ‘grass70’
DATA
define GRASS DATABASE # add your path to grassdata (GRASS GIS database) directory "~
gisdb = os.path.join(os.path.expanduser(“/DATA4/”), “grassdata”)
specify (existing) location and mapset
location = “EUROPE”
mapset = “LANDCOVER”
########### SOFTWARE
if sys.platform.startswith(‘linux’):
we assume that the GRASS GIS start script is available and in the PATH
query GRASS 7 itself for its GISBASE
grass7bin = grass7bin_lin
query GRASS 7 itself for its GISBASE
startcmd = [grass7bin, ‘–config’, ‘path’]
p = subprocess.Popen(startcmd, shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
if p.returncode != 0:
print >>sys.stderr, “ERROR: Cannot find GRASS GIS 7 start script (%s)” % startcmd
sys.exit(-1)
gisbase = out.strip(‘\n\r’)
Set GISBASE environment variable
os.environ[‘GISBASE’] = gisbase
the following not needed with trunk
os.environ[‘PATH’] += os.pathsep + os.path.join(gisbase, ‘extrabin’)
define GRASS-Python environment
gpydir = os.path.join(gisbase, “etc”, “python”)
sys.path.append(gpydir)
########### ########### ########### ########### ########### ########### ########### ########### ###########
########### ########### ########### ########### ########### ########### ########### ########### ###########
########### DATA
Set GISDBASE environment variable
os.environ[‘GISDBASE’] = gisdb
from IPython.display import Image
from pprint import pprint
from subprocess import PIPE
import numpy as np
from grass import script
import subprocess
#looking(script, ‘command’)
import GRASS Python bindings (see also pygrass)
import grass.script as gscript
import grass.script.setup as gsetup
many thanks
Grazia