[GRASS-user] Running a python script using GRASS GIS on a Mac

Shaffiq Somani ssomani at msn.com
Tue Nov 23 21:16:44 PST 2021

Dear Moritz,

Thank you for your advise and I just cut and paste the text from the terminal.  I am making a bit of progress, as shown in the text below.  I am not sure why it can’t find the grass_session as I installed it using the PIP command.  The only solution I can think of is that  GRASS is using its own version of Python and not the Anaconda version.

bash-3.2$ export GRASSBASE="/Applications/GRASS-7.8.app/Contents/Resources/bin/grass78"
bash-3.2$ export GISRC="/Applications/GRASS-7.8.app/Contents/Resources/demolocation/.grassrc78"
bash-3.2$ export PATH="/Applications/GRASS-7.8.app/Contents/Resources/lib:/Applications/GRASS-7.8.app/Contents/Resources/bin:/Applications/GRASS-7.8.app/Contents/Resources/scripts"
bash-3.2$ python gapfill_v3.py
['/Users/shaffiqsomani/PySEBAL_dev/gapfilling', '/Applications/GRASS-7.8.app/Contents/Resources/lib/python38.zip', '/Applications/GRASS-7.8.app/Contents/Resources/lib/python3.8', '/Applications/GRASS-7.8.app/Contents/Resources/lib/python3.8/lib-dynload', '/Applications/GRASS-7.8.app/Contents/Resources/lib/python3.8/site-packages']
Traceback (most recent call last):
  File "gapfill_v3.py", line 20, in <module>
    import grass_session
ModuleNotFoundError: No module named ‘grass_session’

Please let me know if you have any suggestions.  Thanks so much for your assistance.

Kind Regards,


On Nov 23, 2021, at 1:13 AM, Moritz Lennert <mlennert at club.worldonline.be<mailto:mlennert at club.worldonline.be>> wrote:

Hi Shaffiq,

First of all please try to avoid using screenshots of the command line. You should be able to just copy-paste it's contents as text into your email which makes it much easier to read on most devices.

Le 23 novembre 2021 05:26:22 GMT+01:00, Shaffiq Somani <SSomani at msn.com<mailto:SSomani at msn.com>> a écrit :
Dear Moritz,

Thank you for your response since its greatly appreciated.  Sorry, I just saw your message since it went into the spam folder.  I have a couple of questions for you if you have a moment free.  I looked at the Linux environmental variables which is export GRASS_BIN=/usr/bin/grass78, ​but changed it to GRASSBASE and opened up the unix file as shown in the screenshot below.  I still get the following errors. Is there anything else that I am missing or should I be doing this another way.  Thanks.

AFAIK, GRASSBASE is not used in GRASS GIS. Where did you get that from.

I would suggest to set that back to GRASSBIN and try again.


From: Moritz Lennert <mlennert at club.worldonline.be<mailto:mlennert at club.worldonline.be>>
Sent: Monday, November 22, 2021 2:16 AM
To: grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org> <grass-user at lists.osgeo.org<mailto:grass-user at lists.osgeo.org>>; Shaffiq Somani <ssomani at msn.com<mailto:ssomani at msn.com>>
Subject: Re: [GRASS-user] Running a python script using GRASS GIS on a Mac

Hi Shaffiq,

Le 22 novembre 2021 00:48:04 GMT+01:00, Shaffiq Somani <ssomani at msn.com<mailto:ssomani at msn.com>> a écrit :
Dear GRASS Community,

I am trying to run grass as a Python script  for the gapfilling component of PySEBAL where the GitHub directory is shown below.   I have already imported the grass-session using the pip3 command.

PySEBAL GitHub Directory GapFilling

The Windows Environmental Variable setup file is shown below which I tried to follow in the  Jupyter Notebook and  see if I can import GRASS.  Unfortunately, I had no luck as shown in the screenshot.

set GRASSBIN=C:\OSGeo4W64\bin\grass78

As you can see here, GRASSBIN points to the actual 'binary' file that contains the GRASS GIS launch script (grass78). In your example it seems to me that you only point to the directory that contains it, not the actual file. Try adding the name of the file to your path.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-user/attachments/20211124/b6f11a07/attachment.html>

More information about the grass-user mailing list