[GRASS-user] Using grass libraries in python outside of GRASS
DAmico, Ellen
DAmico.Ellen at epa.gov
Wed Jul 29 08:03:37 PDT 2020
Thank you that solved it with some tweaks.
I added GRASSBIN to my Environment variables populated with the grass bat file instead of GISBIN. Then added 'lib', 'bin' and 'scripts' folders to PATH variable. Once I did that that I was able to import grass_session and grass.
It appears to work fine without GISRC set.
Ellen
From: Sajid Pareeth <spareeth at gmail.com>
Sent: Wednesday, July 29, 2020 8:10 AM
To: Markus Neteler <neteler at osgeo.org>
Cc: DAmico, Ellen <DAmico.Ellen at epa.gov>; GRASS user list <grass-user at lists.osgeo.org>
Subject: Re: [GRASS-user] Using grass libraries in python outside of GRASS
Hi
> > The model I need to use (which I did not write) requires python 2.7.
> > I had tried pip install previously but then it still fails with ImportError: No module named grass.script.
> > Do you know what could be causing that?
Interestingly, our docker containers just started to suffer from a
similar (same?) problem:
File "/scripts/test_grass_session.py", line 3, in <module>
import grass.script as grass
ModuleNotFoundError: No module named 'grass'
Weird, we need to investigate.
Grass_session works for me with both python2.7 and 3 in a Osgeo environment with grass 7.8.3
For me, the import modules work in this order in both python versions after pip installation.
>>> import grass_session
>>> from grass_session import Session
>>> import grass.script as grass
For the final script to work, you will have to set environment variables, GISBIN (grass78 root folder) , GISRC (.grassrc78 file in demo location) and add grass78 'lib', 'bin' and 'scripts' folders to PATH variable.
I run the script in python 3, where it worked without setting GISBIN and GISRC variables. I have only tested this approach in Windows 10 yet, and should work fine in Linux as well.
Regards
Sajid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20200729/ee878c40/attachment-0001.html>
More information about the grass-user
mailing list