<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Thank you that solved it with some tweaks.<o:p></o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal">It appears to work fine without GISRC set.<o:p></o:p></p>
<p class="MsoNormal">Ellen<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> Sajid Pareeth <spareeth@gmail.com> <br>
<b>Sent:</b> Wednesday, July 29, 2020 8:10 AM<br>
<b>To:</b> Markus Neteler <neteler@osgeo.org><br>
<b>Cc:</b> DAmico, Ellen <DAmico.Ellen@epa.gov>; GRASS user list <grass-user@lists.osgeo.org><br>
<b>Subject:</b> Re: [GRASS-user] Using grass libraries in python outside of GRASS<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<p class="MsoNormal">Hi <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">> > The model I need to use (which I did not write) requires python 2.7.<br>
> > I had tried pip install previously but then it still fails with ImportError: No module named grass.script.<br>
> > Do you know what could be causing that?<br>
<br>
Interestingly, our docker containers just started to suffer from a<br>
similar (same?) problem:<br>
<br>
File "/scripts/test_grass_session.py", line 3, in <module><br>
import grass.script as grass<br>
ModuleNotFoundError: No module named 'grass'<br>
<br>
Weird, we need to investigate.<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Grass_session works for me with both python2.7 and 3 in a Osgeo environment with grass 7.8.3<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">For me, the import modules work in this order in both python versions after pip installation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><i>>>> import grass_session<br>
>>> from grass_session import Session</i><o:p></o:p></p>
</blockquote>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal"><i>>>> import grass.script as grass</i><o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Regards<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Sajid<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</body>
</html>