[GRASS-user] not able to import and use pygrass

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

On 29/06/15 16:57, Gra wrote:

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

try

import grass.pygrass

pygrass is on the same level as script which you seem to be able to import successfully.

Moritz

On Mon, Jun 29, 2015 at 11:42 AM, Moritz Lennert <
mlennert@club.worldonline.be> wrote:

On 29/06/15 16:57, Gra wrote:

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

try

import grass.pygrass

pygrass is on the same level as script which you seem to be able to import
successfully.

I fixed the documentation in:

https://trac.osgeo.org/grass/changeset/65526

When backported and updated online, it will be visible at:

http://grass.osgeo.org/grass70/manuals/libpython/pygrass_modules.html

The source code and its layout (which influences resulting package layout)
can be browsed here (lib/python directory becomes `grass` package):

https://trac.osgeo.org/grass/browser/grass/trunk/lib/python/

Reviews of documentation are welcome, patches accepted.

Vaclav

On Mon, Jun 29, 2015 at 6:08 PM, Vaclav Petras <wenzeslaus@gmail.com> wrote:

On Mon, Jun 29, 2015 at 11:42 AM, Moritz Lennert

On 29/06/15 16:57, Gra wrote:

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

try

import grass.pygrass

pygrass is on the same level as script which you seem to be able to import
successfully.

I fixed the documentation in:

https://trac.osgeo.org/grass/changeset/65526

When backported and updated online, it will be visible at:

http://grass.osgeo.org/grass70/manuals/libpython/pygrass_modules.html

For the record: the backport has been done and the pages linked here
are up to date.

Markus