[GRASS-user] Using grass libraries in python outside of GRASS
Sajid Pareeth
spareeth at gmail.com
Wed Jul 29 05:10:02 PDT 2020
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/90090346/attachment.html>
More information about the grass-user
mailing list