I am trying to access GRASS from Python (Spyder).
I have:
- Installed via
pip install grass-session
- Started GRASS from OSGEO4W, loaded the mapset and location
- Started Spyder from Anaconda
- Tried to follow https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly with no success
Code:
import os
## grass78 --config
# C:/Program Files/QGIS 3.22.7/apps/grass/grass78
## possible GRASSBIN
# C:\Program Files\QGIS 3.22.7\apps\grass\grass78\bin
# set some common environmental variables, like:
os.environ.update(dict(GRASSBIN = r"C:\Program Files\QGIS 3.22.7\apps\grass\grass78\bin"))
grass7bin_win = r'C:\Program Files\QGIS 3.22.7\bin\grass78.bat'
from grass_session import Session
from grass.pygrass.modules.shortcuts import general as g
errors:
RuntimeError: Cannot find GRASS GIS start script: C:\Program Files\QGIS 3.22.7\apps\grass\grass78\bin, set the right one using the GRASSBIN environm. variable
ModuleNotFoundError: No module named 'grass'
I think this is similar to How to use GRASS GIS in Python standalone? and Finding GRASSBIN on Linux but they're from standalone GRASS installations and I can't work it out still.
Any ideas on how to fix this?