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
https://github.com/spareeth/PySEBAL_dev/tree/version3.7.3/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
set GISRC=C:\OSGeo4W64\apps\grass\grass78\demolocation.grassrc78
set PATH=%PATH%;C:\OSGeo4W64\apps\grass\grass78\lib;C:\OSGeo4W64\apps\grass\grass78\bin;C:\OSGeo4W64\apps\grass\grass78\scripts
Does anyone have ideas or suggestions on how to make GRASS GIS run on the MacOS so I can make the gap fill_v3.py work with minimum alteration for the file. I have seen a few suggestions, on trying to make grass run via python, but I have not had any luck. . Any help you can provide or point me too in the right direction would be greatly appreciated.
Thanks.
Kind Regards,
Shaffiq

Hi Shaffiq,
Le 22 novembre 2021 00:48:04 GMT+01:00, Shaffiq Somani <ssomani@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
https://github.com/spareeth/PySEBAL_dev/tree/version3.7.3/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.
Moritz
Dear GRASS Community,
I did find this previous exchange, that someone has asked the same question before.
https://www.mail-archive.com/grass-user@lists.osgeo.org/msg36682.html
The sudo easy install pip doesn’t really work since since there is no Python version 2.7
I did the remaining steps as shown below and this is the message I received.

- Please note there is an updated python script, that doesn’t have a name but I name it to a.py. The updated is displayed using the following link. I updated the print command by adding ()
https://www.mail-archive.com/grass-user@lists.osgeo.org/msg36683.html
Now I am not sure where to go next.
Any help you can provide would greatly be appreciated. Thanks.
Kind Regards,
Shaffiq
On Nov 21, 2021, at 5:48 PM, Shaffiq Somani <ssomani@msn.com> wrote:
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
https://github.com/spareeth/PySEBAL_dev/tree/version3.7.3/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
set GISRC=C:\OSGeo4W64\apps\grass\grass78\demolocation.grassrc78
set PATH=%PATH%;C:\OSGeo4W64\apps\grass\grass78\lib;C:\OSGeo4W64\apps\grass\grass78\bin;C:\OSGeo4W64\apps\grass\grass78\scripts
Does anyone have ideas or suggestions on how to make GRASS GIS run on the MacOS so I can make the gap fill_v3.py work with minimum alteration for the file. I have seen a few suggestions, on trying to make grass run via python, but I have not had any luck. . Any help you can provide or point me too in the right direction would be greatly appreciated.
Thanks.
Kind Regards,
Shaffiq
<Screen Shot 2021-11-21 at 5.07.03 PM.png>
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user
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.
Kind Regards,
Shaffiq

···
From: Moritz Lennert mlennert@club.worldonline.be
Sent: Monday, November 22, 2021 2:16 AM
To: grass-user@lists.osgeo.org grass-user@lists.osgeo.org; Shaffiq Somani ssomani@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@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
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fspareeth%2FPySEBAL_dev%2Ftree%2Fversion3.7.3%2Fgapfilling&data=04%7C01%7C%7Cf535d63b09244ba1e6fa08d9ad881614%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637731622263517024%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=zPp%2BeqagyPPRsG%2BWpZ0%2B3YrPXhsD5hCYEixbfAX3zhA%3D&reserved=0
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.
Moritz
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@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.
Moritz
________________________________
From: Moritz Lennert <mlennert@club.worldonline.be>
Sent: Monday, November 22, 2021 2:16 AM
To: grass-user@lists.osgeo.org <grass-user@lists.osgeo.org>; Shaffiq Somani <ssomani@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@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
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fspareeth%2FPySEBAL_dev%2Ftree%2Fversion3.7.3%2Fgapfilling&data=04|01||f535d63b09244ba1e6fa08d9ad881614|84df9e7fe9f640afb435aaaaaaaaaaaa|1|0|637731622263517024|Unknown|TWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D|3000&sdata=zPp%2BeqagyPPRsG%2BWpZ0%2B3YrPXhsD5hCYEixbfAX3zhA%3D&reserved=0
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.
Moritz
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
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,
Shaffiq
On Nov 23, 2021, at 1:13 AM, Moritz Lennert <mlennert@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@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.
Moritz
From: Moritz Lennert <mlennert@club.worldonline.be>
Sent: Monday, November 22, 2021 2:16 AM
To: grass-user@lists.osgeo.org <grass-user@lists.osgeo.org>; Shaffiq Somani <ssomani@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@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
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fspareeth%2FPySEBAL_dev%2Ftree%2Fversion3.7.3%2Fgapfilling&data=04%7C01%7C%7Cd44fe3d6f6b8474c3bdd08d9ae50d315%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637732484430999647%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=qfwHowFWkSjB7A00qJOqqF6CBVIQwx0U%2FwFKDYaa0EA%3D&reserved=0
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.
Moritz
Hi Shaffiq,
Am 24.11.2021 06:16 schrieb Shaffiq Somani:
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"
As mentioned earlier, GRASSBASE is not used. This should be GRASSBIN. GRASSBIN is a variable used by grass_session to find the correct GRASS GIS binary.
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’
Are you sure that you have grass_session installed ? It is independent of GRASS GIS, so needs to be installed separately.
Could you just open a terminal, launch the python interpreter, just type 'import grass_session' in there and tell us what happens ?
Moritz
Dear Moritz,
Thanks about GRASSBIN as I missed it. I was able to install grass_session since one of the errors I was making was with the PATH variable. I overwrote the PATH variable instead of append.
I still need to test the grass_session since the python file was producing an error. Not sure if that’s the python file running on the Mac or there’s another issue with grass_session. I think there is enough example items on the web to determine which is which.
Thanks for all your help.
Kind Regards,
Shaffiq
Sent from my iPhone
On Dec 2, 2021, at 5:48 AM, Moritz Lennert <mlennert@club.worldonline.be> wrote:
Hi Shaffiq,
Am 24.11.2021 06:16 schrieb Shaffiq Somani:
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"
As mentioned earlier, GRASSBASE is not used. This should be GRASSBIN. GRASSBIN is a variable used by grass_session to find the correct GRASS GIS binary.
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’
Are you sure that you have grass_session installed ? It is independent of GRASS GIS, so needs to be installed separately.
Could you just open a terminal, launch the python interpreter, just type 'import grass_session' in there and tell us what happens ?
Moritz