[GRASS-user] pygrass how to start

Gra graziaz at gmail.com
Thu Mar 29 07:29:46 PDT 2018


Hi
could you please help me starting with pygrass library.

this is my test and the error (at the end)

THANKS
Grazia

#!/usr/bin/env python

# Example for pyGRASS usage - vector API

import os
import sys
import subprocess

########### ########### ########### ########### ###########
########### ########### ########### ###########
########### ########### ########### ########### ###########
########### ########### ########### ###########
# path to the GRASS GIS launch script
# Linux
grass7bin_lin = 'grass'
# DATA
# define GRASS DATABASE # add your path to grassdata (GRASS GIS
database) directory "~
gisdb = os.path.join(os.path.expanduser("/SERVER_DATA/"), "grassdata")
# specify (existing) location and mapset
location = "EnRoute"
mapset = "in_data"

########### 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)
########### ########### ########### ########### ###########
########### ########### ########### ###########

# Set GISDBASE environment variable
os.environ['GISDBASE'] = gisdb

# looking(script, '*command*')
# import GRASS Python bindings (see also pygrass)
import grass.script as gscript
import grass.script.setup as gsetup
import grass.script as grass



###########
# launch session
gsetup.init(gisbase,
            gisdb, location, mapset)

gscript.message('Current GRASS GIS 7 environment:')
# print gscript.gisenv()



from grass.pygrass.modules.shortcuts import general as g
from grass.pygrass.vector import VectorTopo



in_vect = 'core_IT028L2'

data = vector.VectorTopo('core_IT028L2')

data.open()






Current GRASS GIS 7 environment:
Traceback (most recent call last):
  File "/SERVER_DATA/PycharmProjects/EnRoute/back/Soil_sealing.py",
line 75, in <module>
    from grass.pygrass.vector import VectorTopo
  File "/usr/lib/grass72/etc/python/grass/pygrass/vector/__init__.py",
line 5, in <module>
    import grass.lib.gis as libgis
  File "/usr/lib/grass72/etc/python/grass/lib/gis.py", line 23, in <module>
    _libs["grass_gis.7.2.1"] = load_library("grass_gis.7.2.1")
  File "/usr/lib/grass72/etc/python/grass/lib/ctypes_loader.py", line
62, in load_library
    return self.load(path)
  File "/usr/lib/grass72/etc/python/grass/lib/ctypes_loader.py", line
78, in load
    raise ImportError(e)
ImportError: libgrass_datetime.7.2.1.so: cannot open shared object
file: No such file or directory

Process finished with exit code 1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20180329/39ee9663/attachment.html>


More information about the grass-user mailing list