grass-addons icon indicating copy to clipboard operation
grass-addons copied to clipboard

g.extension vs r.green

Open jachym opened this issue 5 years ago • 19 comments

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

image

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

jachym avatar Sep 01 '20 07:09 jachym

I suppose it is an addon bug since other addons can be installed.

The replacement of python with python3 is needed in g.extension.

neteler avatar Sep 01 '20 17:09 neteler

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?

jachym avatar Sep 02 '20 06:09 jachym

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?

tmszi avatar Sep 02 '20 08:09 tmszi

Shall we replace those "offending" symbols in r.green or modify anything else? Any suggestion, @zarch ?

neteler avatar Oct 04 '20 09:10 neteler

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_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)

r_green_gshp_technical_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.

tmszi avatar Oct 04 '20 13:10 tmszi

Any suggestion how to deal with this?

neteler avatar Oct 11 '20 07:10 neteler

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_wxmsw

r.green.gshp.technical module ui, OS GNU/Linux (wxGTK)

r_green_gshp_technical_wxgtk

I think it would be appropriate to replace these special symbols.

How do we put this on command console? after the error message?

anissa293 avatar Oct 12 '20 02:10 anissa293

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).

  1. Launch your favourite text editor (Notepad++...) with Admin rights.
  2. Open in text editor this file C:\Program Files\GRASS GIS 7.8\scripts\g.extension.py
  3. 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='')
  1. Save edited file
  2. Install r.green Add-On with command: g.extension r.green or via GUI
  3. Try launch some r.green module e.g. r.green.gshp.technical

tmszi avatar Oct 12 '20 05:10 tmszi

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 Capture

and the same error message once i try to install the r.green Capture 1

anissa293 avatar Oct 12 '20 06:10 anissa293

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 Capture

and the same error message once i try to install the r.green Capture 1

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='')

tmszi avatar Oct 12 '20 06:10 tmszi

it works perfectly now! thanks a lot @tmszi

anissa293 avatar Oct 12 '20 07:10 anissa293

it works perfectly now! thanks a lot @tmszi

You are welcome :-).

tmszi avatar Oct 12 '20 07:10 tmszi

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 sys.exit(main(options, flags)) File "C:\Users\ANIA\AppData\Roaming\GRASS7\addons/scripts/ r.green.hydro.optimal.py", line 180, in main p_max) File "C:\Users\ANIA\AppData\Roaming\GRASS7\addons\etc\r.gr een\libhydro\optimal.py", line 357, in find_segments count, p_max) File "C:\Users\ANIA\AppData\Roaming\GRASS7\addons\etc\r.gr een\libhydro\optimal.py", line 231, in recursive_plant cat, line, count, p_max) File "C:\Users\ANIA\AppData\Roaming\GRASS7\addons\etc\r.gr een\libhydro\optimal.py", line 243, in check_plant fun_h = interpolate.interp1d(prog, h, bounds_error=False, fill_value=0) NameError: name 'interpolate' is not defined (Tue Oct 13 11:46:33 2020) Command finished (1 sec)

I have installed scipy and numpy as required and it shown in the command below: Capture 1

Appreciate it very much if anyone could help me on this matter. I have very little to none knowledge on python

anissa293 avatar Oct 13 '20 03:10 anissa293

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.

baharmon avatar Oct 13 '20 05:10 baharmon

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?

anissa293 avatar Oct 13 '20 06:10 anissa293

I already tried to check in Grass terminal btw, and it says that I have scipy. Unsure why this warning message appears :( Capture 1

Capture

anissa293 avatar Oct 13 '20 08:10 anissa293

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.

  1. 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

  2. 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"
  1. 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
  1. 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
  1. Launch GRASS GIS and r.green module r.green.hydro.optimal

tmszi avatar Oct 13 '20 09:10 tmszi

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) :

  1. Launch cmd
  2. Change dir in cmd cd "C:\Program Files\GRASS GIS 7.8\Python37"
  3. Get list of installed Python libs python.exe Scripts\pip3.exe freeze list

Or simple way via GUI Python shell (Layer Manager -> Python tab)

  1. import scipy (run without error)

tmszi avatar Oct 13 '20 11:10 tmszi

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 Capture 1

anissa293 avatar Oct 14 '20 06:10 anissa293