[GRASS-dev] No module named grass.script

Hi,
I've just installed OSGEO4W64
Grass 7.8.2 works (alone), as does Grass functionality through QGIS 3.10.2 (with Grass 7.8.2).

I am now trying to put together a python 3.7 script using PyCharm 2019.3.3 Community edition.
I start PyCharm using the cmd script below.

My python script fails (in the Pycharm IDE) on import grass.script as gscript.

I have set GISBASE, GRASSBIN and PATH in the windows env setup.
Please can someone point me in the correct direction to be able to write python scripts using grass modules, in pycharm.

Thanks and regards,
Zoltan.

My pycharm startup script is:
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass78\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass78\lib
path %PATH%;%OSGEO4W_ROOT%\apps\Qt5\bin
path %PATH%;%OSGEO4W_ROOT%\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python
set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\grass\grass78\etc\python\grass
SET PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37
SET PYTHONPATH=%PYTHONHOME%;%PYTHONHOME%\Scripts
PATH %PYTHONPATH%;%PATH%

set PATH=C:\Program Files\Git\bin;%PATH%

start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2\bin\pycharm64.exe"

--

=============================================
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

P.O. Box 7, Muizenberg 7950, South Africa.

Mobile: +27-83-6004028 (WhatsApp only)
Qatar: +974 5083 2722 www.geograph.co.za

Hi Zoltan,

On Sun, Feb 9, 2020 at 8:15 AM Zoltan Szecsei <zoltans@geograph.co.za> wrote:

set
PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\grass\grass78\etc\python\grass

The path needs to be just to …\etc\python, grass is already the package name (you can examine the directory to see if there is init.py file.

There are different approaches to this. Modification of what you are doing is here, trying to get the path from GRASS GIS executable (here just grass):

https://github.com/wenzeslaus/try-grass-in-jupyter/blob/master/notebook.ipynb

Another one is grass-session/grass_session:

https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python:_GRASS_GIS_7_with_an_external_library:_grass-session

HTH,
Vaclav

Hi,

On Mon, Feb 10, 2020 at 2:50 PM Vaclav Petras <wenzeslaus@gmail.com> wrote:

Hi Zoltan,

On Sun, Feb 9, 2020 at 8:15 AM Zoltan Szecsei <zoltans@geograph.co.za> wrote:

set
PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\grass\grass78\etc\python\grass

The path needs to be just to ...\etc\python, grass is already the package name (you can examine the directory to see if there is __init__.py file.

There are different approaches to this. Modification of what you are doing is here, trying to get the path from GRASS GIS executable (here just `grass`):

https://github.com/wenzeslaus/try-grass-in-jupyter/blob/master/notebook.ipynb

Another one is grass-session/grass_session:

https://grasswiki.osgeo.org/wiki/Working_with_GRASS_without_starting_it_explicitly#Python:_GRASS_GIS_7_with_an_external_library:_grass-session

Once figured out, please add some notes here:

https://grasswiki.osgeo.org/wiki/Tools_for_Python_programming#PyCharm_IDE

Thanks,
Markus