0

I'm trying to use grass.script and grass_session in a standalone python script on my MacOS device, but I always get error messages that tells me specific environment variables aren't set in the right way:

RuntimeError: Cannot find GRASS GIS start script: /Applications/GRASS-8.2.app/, set the right one using the GRASSBIN environm. variable
RuntimeError: GRASS GIS start script: /Applications/GRASS-8.2.app/Contents/MacOS/grass.sh --config path, return as GISBASE a directory (Rebuilding Addon HTML manual pages index...
    Rebuilding Addon menu...
    /Applications/GRASS-8.2.app/Contents/Resources) that do not exist.

I already tried a lot of different environment variable combinations without success:

export GRASSBIN="/Applications/GRASS-8.2.app/Contents/MacOS/Grass.sh"
export GRASSBIN="/Applications/GRASS-8.2.app/"
export GISBASE=/Applications/GRASS-8.2.app/Contents/Resources

If I'm running the desktop version of GRASS GIS and execute the env command in the shell, I'm getting the following ouput:

MANPATH=/Applications/GRASS-8.2.app/Contents/Resources/docs/man:/Users/jonas.frei/Library/GRASS/8.2/Addons/docs/man:/opt/homebrew/share/man:
GRASS_PYTHON=/Applications/GRASS-8.2.app/Contents/Resources/bin/python3
TERM_PROGRAM=Apple_Terminal
GISBASE_SYSTEM=/Library/GRASS/8.2
GRASS_GNUPLOT=gnuplot -persist
GRASS_PAGER=more
GISRC=/var/folders/tb/v92zl5yn4wx7503j9y4k5tls9gd4by/T/grass8-jonas.frei-44418/gisrc
TERM=xterm-256color
SHELL=/bin/bash
HISTSIZE=
TMPDIR=/var/folders/tb/v92zl5yn4wx7503j9y4k5tls9gd4by/T/grass8-jonas.frei-44418
HOMEBREW_REPOSITORY=/opt/homebrew
TERM_PROGRAM_VERSION=443
MallocSpaceEfficient=0
MallocNanoZone=0
TERM_SESSION_ID=6FC3C0CC-BF3B-460B-BA15-20E31299E75B
PYTHONEXECUTABLE=/Applications/GRASS-8.2.app/Contents/Resources/bin/python
HISTFILESIZE=
USER=jonas.frei
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.Coegc0wRwg/Listeners
__CF_USER_TEXT_ENCODING=0x52F6917E:0x0:0x0
GISBASE=/Applications/GRASS-8.2.app/Contents/Resources
PATH=/Applications/GRASS-8.2.app/Contents/Resources/bin:/Applications/GRASS-8.2.app/Contents/Resources/scripts:/Users/jonas.frei/Library/GRASS/8.2/Addons/bin:/Users/jonas.frei/Library/GRASS/8.2/Addons/scripts:/Users/jonas.frei/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jonas.frei/miniconda3/bin:/Documents/programms/brew/bin:/Users/jonas.frei/Documents/programms/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/GRASS-8.2.app/Contents/Resources/bin:/Applications/GRASS-8.2.app/Contents/Resources/scripts:/Users/jonas.frei/Library/GRASS/8.2/Addons/bin:/Users/jonas.frei/Library/GRASS/8.2/Addons/scripts:/Users/jonas.frei/.pyenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jonas.frei/miniconda3/bin:/Documents/programms/brew/bin:/Users/jonas.frei/Documents/programms/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:${PATH}:/usr/local/go/bin:/usr/local/go/bin
LD_RUN_PATH=/Applications/GRASS-8.2.app/Contents/Resources/lib
__CFBundleIdentifier=com.apple.Terminal
PWD=/Users/jonas.frei
GIS_LOCK=44418
GRASS_PROJSHARE=/Applications/GRASS-8.2.app/Contents/Resources/share/proj
XPC_FLAGS=0x0
GDAL_DATA=/Applications/GRASS-8.2.app/Contents/Resources/share/gdal
GRASS_HTML_BROWSER_MACOSX=-b com.apple.helpviewer
GRASS_VERSION=8.2.0
GRASS_FONT_CAP=/Users/jonas.frei/Library/GRASS/8.2/Addons/etc/fontcap
XPC_SERVICE_NAME=0
HOME=/Users/jonas.frei
SHLVL=4
PYENV_SHELL=bash
GRASS_HTML_BROWSER=/Applications/GRASS-8.2.app/Contents/Resources/etc/html_browser_mac.sh
HOMEBREW_PREFIX=/opt/homebrew
PYTHONPATH=/Applications/GRASS-8.2.app/Contents/Resources/etc/python
LOGNAME=jonas.frei
LC_CTYPE=UTF-8
GRASS_ADDON_ETC=/Users/jonas.frei/Library/GRASS/8.2/Addons/etc:/Library/GRASS/8.2/Addons/etc
GISBASE_USER=/Users/jonas.frei/Library/GRASS/8.2
HOMEBREW_CELLAR=/opt/homebrew/Cellar
INFOPATH=/opt/homebrew/share/info:
GRASS_ADDON_BASE=/Users/jonas.frei/Library/GRASS/8.2/Addons
_=/usr/bin/env
1
  • 1
    Are you setting the environment variables at the start of your python script? i.e. os.environ['GRASS_BASE']=....
    – Micha
    Jun 20 at 20:00

1 Answer 1

1

I finally found the solution:

export GRASSBIN=/Applications/GRASS-8.2.app/Contents/Resources/bin/grass

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.