I'm trying to use GRASS module in a Python Skript. I already checked this:
Is it possible to use GRASS GIS in Python stand alone scripts?
and this Using Python script to control GRASS GIS from outside?
but it doesn't help with my problem.
I did pip install grass-session which worked well. My script is just:
import grass_session and when I run it I get the error RuntimeError: Cannot find GRASS GIS start script: 'grass', set the right one using the GRASSBIN environm. variable.
First I tried GRASSBIN="$path\\to\\software\\grass\\grass78 python grass.py" as suggested in
https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly in the block Python: GRASS GIS 7 with an external library: grass-session but I still got the same error.
After checking http://osgeo-org.1560.x6.nabble.com/GRASSBIN-environment-variable-td5413301.html I solved this error adding the following line before the import line: os.environ['GRASSBIN']=r"path\to\software\grass\grass78", although I feel this only should be necessary if my grass version is different from 7.8.
Now when I run these two lines first I'm happy to see that I don't get the error again but after a while I notice that nothing happens. It keeps running without any exit code unless I stop the script manually. I would expect the script to import the module and finish with exit code 0.
I have grass gis 7.8.2. installed with QGIS and Python 3.7 and working on Windows 10 Pro 64 bit.
import grass.script as grassModuleNotFoundError: No module named 'grass.script'; 'grass' is not a package– anplaceb Aug 26 '20 at 08:46grass.message('--- GRASS GIS 7: Current GRASS GIS 7 environment:')The error is very long and I can only copy the last part:grass.exceptions.CalledModuleError: Module run None g.gisenv -n ended with error Process ended with non-zero return code 3221225781. See errors in the (error) output.– anplaceb Aug 26 '20 at 09:08pip install grass. See edits above. – Micha Aug 27 '20 at 08:03grass.exceptions.CalledModuleError: Module run None g.gisenv -n ended with error Process ended with non-zero return code 3221225781. See errors in the (error) output.by changing 'etc' to 'Python' in the gpydir path, which I did just for trying and I was surprised to see that that way I avoid the import error, but to be honest I'm not sure why – anplaceb Aug 31 '20 at 09:16