grass-addons
grass-addons copied to clipboard
g.extension vs r.green
Describe the bug Can't install r.green via g.extension (linux)
To Reproduce Steps to reproduce the behavior:
g.extension r.green
Expected behavior Success install
Screenshots

System description (please complete the following information):
- Operating System: Windows server 2019
- GRASS GIS version 7.8.3 from OSGeo4W
Additional context
If commented out in g.extension:
#for filename in pyfiles:
# with fileinput.FileInput(filename, inplace=True) as file:
# for line in file:
# print(line.replace(
# "#!/usr/bin/env python\n",
# "#!/usr/bin/env python3\n"
# ), end='')
Things work
I suppose it is an addon bug since other addons can be installed.
The replacement of python with python3 is needed in g.extension.
My estimation is, that the is some "strange character" in the input file, so that replace fails. Maybe replacing just the first line would help. This can occur in any future extension
Also, if on non-Linux platform (aka windows), the replacement is not necessary, since Windows ignore it, right?
My estimation is, that the is some "strange character" in the input file, so that replace fails. Maybe replacing just the first line would help. This can occur in any future extension
Yes it is. Lambda symbol and others. fileinput.FileInput() method open file with default OS system encoding. It is possible define openhook param arg (using the given encoding), but not with inplace=True param arg. On GNU/Linux, I did not notice any problem with the installation of the r.green extension.
Also, if on non-Linux platform (aka windows), the replacement is not necessary, since Windows ignore it, right?
Shall we replace those "offending" symbols in r.green or modify anything else? Any suggestion, @zarch ?
If commented out in g.extension (as mentioned above), r.green module installation work:
# for filename in pyfiles:
# with fileinput.FileInput(filename, inplace=True) as file:
# for line in file:
# print(line.replace(
# "#!/usr/bin/env python\n",
# "#!/usr/bin/env python3\n"
# ), end='')
But rendering special symbol in module ui is incorrect on MS WIndows (wxMSW).
r.green.gshp.technical module ui, OS MS Windows (wxMSW)

wxPython use default encoding (according locale):
import wx
locale = wx.Locale()
locale.GetSystemEncodingName()
windows-1252
Lambda symbol is UTF-8.
r.green.gshp.technical module ui, OS GNU/Linux (wxGTK)

wxPython use default encoding (according locale):
import wx
locale = wx.Locale()
locale.GetSystemEncodingName()
UTF-8
I think it would be appropriate to replace these special symbols.
Any suggestion how to deal with this?
hello, i encountered similar issue when installing r.green addons, and no issue on installing other addons. i'm using grass 7.8.3 on windows. any help to solve this issue? I saw
If commented out in g.extension (as mentioned above), r.green module installation work:
# for filename in pyfiles: # with fileinput.FileInput(filename, inplace=True) as file: # for line in file: # print(line.replace( # "#!/usr/bin/env python\n", # "#!/usr/bin/env python3\n" # ), end='')But rendering special symbol in module ui is incorrect on MS WIndows (wxMSW).
r.green.gshp.technical module ui, OS MS Windows (wxMSW)
r.green.gshp.technical module ui, OS GNU/Linux (wxGTK)
I think it would be appropriate to replace these special symbols.
How do we put this on command console? after the error message?
hello, i encountered similar issue when installing r.green addons, and no issue on installing other addons. i'm using grass 7.8.3 on windows. any help to solve this issue? I saw How do we put this on command console? after the error message?
Hello, here's how to install r.green Add-On (OS MS Windows, WIn GRASS GIS 7.8.3 installation).
- Launch your favourite text editor (Notepad++...) with Admin rights.
- Open in text editor this file C:\Program Files\GRASS GIS 7.8\scripts\g.extension.py
- Go to line code ~1148 comment this lines (1148-1154 including):~ when you find this uncommented code (code bellow in the install_extension_win() function) and comment them (according code below):
# for filename in pyfiles:
# with fileinput.FileInput(filename, inplace=True) as file:
# for line in file:
# print(line.replace(
# "#!/usr/bin/env python\n",
# "#!/usr/bin/env python3\n"
# ), end='')
- Save edited file
- Install r.green Add-On with command:
g.extension r.greenor via GUI - Try launch some r.green module e.g.
r.green.gshp.technical
hello @tmszi thank you very much for the response!
I did exactly as you said however it still doesnt work out
below is the edited g.extension py
and the same error message once i try to install the r.green
hello @tmszi thank you very much for the response!
I did exactly as you said however it still doesnt work out
below is the edited g.extension py
and the same error message once i try to install the r.green
I think you have another GRASS GIS version than I have and therefore line numbers (step no. 3 in my previous message) aren't correct.
According screenshot with error you send go to line 1055, and you will see this code:
for filename in pyfiles:
with fileinput.FileInput(filename, inplace=True) as file:
for line in file:
print(line.replace(
"#!/usr/bin/env python\n",
"#!/usr/bin/env python3\n"
), end='')
and comment this lines (add # comment symbol before these lines)
# for filename in pyfiles:
# with fileinput.FileInput(filename, inplace=True) as file:
# for line in file:
# print(line.replace(
# "#!/usr/bin/env python\n",
# "#!/usr/bin/env python3\n"
# ), end='')
it works perfectly now! thanks a lot @tmszi
it works perfectly now! thanks a lot @tmszi
You are welcome :-).
hi @tmszi and all,
I have managed to install the r.green addon and run some modules. However when i tried to run the r.green.hydro.optimal, error message on the scipy requirement appeared:
WARNING: You should install scipy to use this module: pip install scipy
WARNING: You should install scipy to use this module: pip install scipy
WARNING: You should install scipy to use this module: pip install scipy
WARNING: You should install scipy to use this module: pip install scipy
Traceback (most recent call last):
File "C:\Users\ANIA\AppData\Roaming\GRASS7\addons/scripts/
r.green.hydro.optimal.py", line 189, in
I have installed scipy and numpy as required and it shown in the command below:
Appreciate it very much if anyone could help me on this matter. I have very little to none knowledge on python
You may need to compile grass with scipy for python 3. Maybe try using the osgeo4w installer with advanced settings. In the install check all the python3 choices in command line utilities, check grass in desktop apps, and check python3-scipy in libraries.
hi @baharmon i did exactly as you said and the same error message still appear. WARNING: You should install scipy to use this module: pip install scipy WARNING: You should install scipy to use this module: pip install scipy
Is there a way to check of whether scipy is properly installed and detected by Grass?
I already tried to check in Grass terminal btw, and it says that I have scipy. Unsure why this warning message appears :(
hi @tmszi and all,
I have managed to install the r.green addon and run some modules. However when i tried to run the r.green.hydro.optimal, error message on the scipy requirement appeared:
Hi anissa293, here's how to install python additional scipy lib (OS MS Windows, Standalone Win GRASS GIS 7.8 installation). I tested on 64 bit OS Win 10, with Standalone GRASS GIS 64 bit installer.
-
Download numpy and scipy windows binary package from this page Unofficial Windows Binaries for Python Extension Packages. Choose between 32/64 bit according your GRASS GIS installation. 1.1 64 bit GRASS GIS version: numpy, scipy 1.2 32 bit GRASS GIS version: numpy, scipy
-
GRASS GIS is distributed with own Python version. First launch new cmd (command line program) with Admin rights. Change dir with following command in cmd:
cd "C:\Program Files\GRASS GIS 7.8\Python37"
- Install numpy python bin lib first with following command in the cmd:
Change PATH_TO_DOWNLOADED_NUMPY_WHL_FILE to the right path (my path is e.g. C:\Users\IEUser\Desktop\numpy-1.18.5+mkl-cp37-cp37m-win_amd64.whl)
python.exe Scripts\pip3.exe install PATH_TO_DOWNLOADED_NUMPY_WHL_FILE
- Install scipy python bin lib with following command in the cmd:
Change PATH_TO_DOWNLOADED_SCIPY_WHL_FILE to the right path (my path is e.g. C:\Users\IEUser\Desktop\scipy-1.4.1-cp37-cp37m-win_amd64.whl)
python.exe Scripts\pip3.exe install PATH_TO_DOWNLOADED_SCIPY_WHL_FILE
- Launch GRASS GIS and r.green module
r.green.hydro.optimal
I already tried to check in Grass terminal btw, and it says that I have scipy. Unsure why this warning message appears :(
If you want verify that GRASS GIS Python has scipy lib installed (GRASS GIS has own Python in the installation directory: C:\Program Files\GRASS GIS 7.8\Python37) :
- Launch cmd
- Change dir in cmd
cd "C:\Program Files\GRASS GIS 7.8\Python37" - Get list of installed Python libs
python.exe Scripts\pip3.exe freeze list
Or simple way via GUI Python shell (Layer Manager -> Python tab)
import scipy(run without error)
Hi anissa293, here's how to install python additional scipy lib (OS MS Windows, Standalone Win GRASS GIS 7.8 installation). I tested on 64 bit OS Win 10, with Standalone GRASS GIS 64 bit installer.
hi @tmszi it finally works! thanks a lot for this. I also checked again the scipy lib in Grass Python is installed. Hopefully no more issues after this fingercrossed