Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Robin, After installing from python-fmask source as described I got the same error message as you did on: from fmask import fmask (just importing fmask worked also before). The problem seems to be that fmask (including it`s C components) gets installed in /usr/local/. See: https://github.com/ubarsc/python-fmask/issues/19 You can fix that by specifying /usr as a prefix during install: sudo python3 setup.py install --prefix=/usr (note that I also had to specifically call setup.py with python3 which was an error in my initial installation script.) When python-fmask gets available on PyPi, I guess this will be taken care of… If you set the PYTHONPATH environment variable before starting GRASS GIS, GRASS should temporarily add the path to the GRASS python libs (but nothing more). If you use a prepackaged GRASS installation, it is compiled against a specific Python version (usually system Python). You can see which Python installation GRASS is using by typing: echo $GRASS_PYTHON So, if you want to use your conda Python in GRASS (despite possible issues other places), my understanding is that you would need to point GRASS_PYTHON variable to conda python. However, with the installation described above, GRASS should find fmask and _fillminima from fmask… In the long run, this will be the most convenient solution for an addon. For the time being, the installation procedure could be added to the manual as a note (and probably as an error message if import fails), until it becomes available on PyPi. Hope that helps. Cheers Stefan From: robin Sent: søndag 5. april 2020 19:13 To: Stefan Blumentrath Subject: Re: [GRASS-user] Install package for add-on in /usr/bin/python3 Hi Stefan, thank you very much!! Why does my PYTHONPATH needs to point to the system-python? So the issue is, that I would like to have a script that I can run from within GRASS with launch user-defined script. I created a conda environment (“spatial”) and installed python-fmask with: conda install -c conda-forge python-fmask This automativally installes python3.8.2, fmask and rios in: home/robin/miniconda3/envs/spatial/lib/python3.8/site-packages/ I then added this path in my .bashrc (I thought I needed to put it in the .profile, but this didn’t work for some reason) my PYTHONPATH with: export PYTHONPATH=/home/robin/miniconda3/envs/spatial/lib/python3.8/site-packages I then did a source .bashrc and when printing the PYTHONPATH with echo $PYTHONPATH it prints /home/robin/miniconda3/envs/spatial/lib/python3.8/site-packages I then made a little test script where I wanted to test if the fmask-import and rios-import works from within GRASS # 1 #! /usr/bin/env python3 2 3 import sys 4 import os 5 6 for i in sys.path: 7 print(i) 8 9 print("PYTHONPATH") 10 print(os.environ["PYTHONPATH"]) 11 12 import fmask 13 import rios 13 import rios # When importing this script in GRASS with the “launch user-defined script”-option, the output is: /home/robin/Desktop /usr/lib/grass78/etc/python /usr/lib/python36.zip /usr/lib/python3.6 /usr/lib/python3.6/lib-dynload /home/robin/.local/lib/python3.6/site-packages /usr/local/lib/python3.6/dist-packages /usr/lib/python3/dist-packages PYTHONPATH /usr/lib/grass78/etc/python Traceback (most recent call last): File "/home/robin/Desktop/test.py", line 12, in import fmask ModuleNotFoundError: No module named 'fmask' I don’t know why the PYTHONPATH is different when run from GRASS. Probably I’m just not understanding something really basic. If so I’m really sorry. It’s just a little frustrating to spend so much time in something so basic. Anyways: Thanks so much for the help! Cheers, Robin On 05.04.2020 14:35, Stefan Blumentrath wrote: Did you check that your pythonpath again points to system python. And can you share your code, esp. the imports. That would simplify testing... Sent from Outlook Mobile<https://aka.ms/blhgte> From: robin kohrs <mailto:robin.ko...@uni-jena.de> Sent: Sunday, April 5, 2020 11:04:02 AM To: Stefan Blumentrath <mailto:stefan.blumentr...@nina.no> Subject: Re: [GRASS-user] Install package for add-on in /usr/bin/python3 Hi Stefan, thank you very much for the answer! That would be great if it'd become a standard python package! I managed to install everything as you explained it. But when I run: In [1]: from fmask import fmask I still get ModuleNotFoundError: No module named 'rios' I guess this is, because they are still in seperate folders right? When I copy everything from the installed rios into fmask (I know this seems really wrong...) and then do : In [2]: from fmask import fmask ImportError: cannot import name '_fillminima' I'm sorry for these basic questions, but I just can't find a solution:/ cheers and thanks a lot!! Robin On 04.04.20 20:56, Stefan Blumentrath wrote: > Hi Robin, > >
Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Robin, The errors you encountered after setting the python path, occurred because fmask depends on another, non-standard Python package, namely rios (that would have to be added to the PYTHONPATH as well). Yet, it seems there is some more interest in getting python-fmask (and thus also RIOS) available as a standard python package. See: https://github.com/ubarsc/python-fmask/issues/30 So, your problem might get solved "upstreams". Meanwhile you could install both packages manually into your standard Python installation as follows: wget https://github.com/ubarsc/rios/releases/download/rios-1.4.10/rios-1.4.10.zip unzip rios-1.4.10.zip cd rios-1.4.10/ sudo python setup.py install cd .. wget https://github.com/ubarsc/python-fmask/releases/download/pythonfmask-0.5.4/python-fmask-0.5.4.zip unzip -q python-fmask-0.5.4.zip cd python-fmask-0.5.4/ python setup.py build sudo python setup.py install For me (on Ubuntu 18.04) this gives: $ ipython Python 3.6.8 (default, Oct 7 2019, 12:59:55) Type 'copyright', 'credits' or 'license' for more information IPython 7.13.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import fmask In [2]: fmask.__version__ Out[2]: '0.5.4' In [3]: import rios In [4]: rios.__version__ Out[4]: '1.4.10' Cheers Stefan -Original Message- From: Robin Kohrs Sent: tirsdag 31. mars 2020 15:42 To: Stefan Blumentrath Cc: Markus Neteler ; GRASS user list Subject: Re: [GRASS-user] Install package for add-on in /usr/bin/python3 Hi Stefan, thank you very much for the effort and the patience in answering! I'll definitely give this a try. I already have so many issues on my computer, one more doesn't matter;) thanks again and best regards, Robin Citando Stefan Blumentrath : > Hi Robin, > > You could try setting the GRASS_PYTHON environment variable to your > Python installation with fmask. > > import os > os.environ['GRASS_PYTHON'] = '/YOUR/PYTHON/PATH' > > As Markus indicates that can cause other issues. > > You may also have a look at https://github.com/zarch/grass-session > for inspiration. > > Hope that gives you at least a lead... > > Cheers > Stefan > > > -Original Message- > From: grass-user On Behalf Of > Robin Kohrs > Sent: tirsdag 31. mars 2020 09:25 > To: Markus Neteler > Cc: GRASS user list > Subject: Re: [GRASS-user] Install package for add-on in > /usr/bin/python3 > > Hi Markus, > > thank you very much for your answer and the help! > Do you have any idea what I could do to make the fmask-package > "locatable" for the python-interpreter that grass is using? > > I tried the following options, but I guess I just don't know > sufficiently about how python and grass really work together: > > My python-script looks more or less like this: > --- > #!/usr/bin/env python3 > > import sys > > print("SYS PATH") > print(sys.path) > print("") > print("SYS EXECUTABLE") > print(sys.executable) > > import grass.script as grass > from rios import fileinfo # that's where it fails from fmask import > fmask > > --- > > That's why I tried until now: > > - I created an environment with conda and installed python-fmask via > "conda install -c conda-forge python-fmask". The function > "fmask_sentinel2Stacked.py" lies in > "/home/robin/miniconda3/bin/fmask_sentinel2Stacked.py". > > - When I open an interactive python-shell and import fmask and rios > and the type: "fmask.__file__" it gives me > "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/fmask/__init__.py" > > - I then added > "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/" to > the variable PYTHONPATH in my .bashrc > > - When I now start the interpreter that grass uses from the command > line by typing "/usr/bin/pyton3" I can import fmask and rios > > - However when I run the script with grass it always says that there > is no package names rios. Moreover the path I added to PYTHONPATH is > not printed when it executes "sys.path" in my grass script > > > I'm sorry for this little confusing question. But in case someone > has any idea how I could make grass find fmask, would be super highly > appreciated:) > > thanks a lot in advance! Cheers > Robin > > Citando Markus Neteler : > >> Hi Robin, >> >> On Sat, Mar 21, 2020 at 6:15 PM Robin Ko
Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Stefan, thank you very much for the effort and the patience in answering! I'll definitely give this a try. I already have so many issues on my computer, one more doesn't matter;) thanks again and best regards, Robin Citando Stefan Blumentrath : Hi Robin, You could try setting the GRASS_PYTHON environment variable to your Python installation with fmask. import os os.environ['GRASS_PYTHON'] = '/YOUR/PYTHON/PATH' As Markus indicates that can cause other issues. You may also have a look at https://github.com/zarch/grass-session for inspiration. Hope that gives you at least a lead... Cheers Stefan -Original Message- From: grass-user On Behalf Of Robin Kohrs Sent: tirsdag 31. mars 2020 09:25 To: Markus Neteler Cc: GRASS user list Subject: Re: [GRASS-user] Install package for add-on in /usr/bin/python3 Hi Markus, thank you very much for your answer and the help! Do you have any idea what I could do to make the fmask-package "locatable" for the python-interpreter that grass is using? I tried the following options, but I guess I just don't know sufficiently about how python and grass really work together: My python-script looks more or less like this: --- #!/usr/bin/env python3 import sys print("SYS PATH") print(sys.path) print("") print("SYS EXECUTABLE") print(sys.executable) import grass.script as grass from rios import fileinfo # that's where it fails from fmask import fmask --- That's why I tried until now: - I created an environment with conda and installed python-fmask via "conda install -c conda-forge python-fmask". The function "fmask_sentinel2Stacked.py" lies in "/home/robin/miniconda3/bin/fmask_sentinel2Stacked.py". - When I open an interactive python-shell and import fmask and rios and the type: "fmask.__file__" it gives me "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/fmask/__init__.py" - I then added "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/" to the variable PYTHONPATH in my .bashrc - When I now start the interpreter that grass uses from the command line by typing "/usr/bin/pyton3" I can import fmask and rios - However when I run the script with grass it always says that there is no package names rios. Moreover the path I added to PYTHONPATH is not printed when it executes "sys.path" in my grass script I'm sorry for this little confusing question. But in case someone has any idea how I could make grass find fmask, would be super highly appreciated:) thanks a lot in advance! Cheers Robin Citando Markus Neteler : Hi Robin, On Sat, Mar 21, 2020 at 6:15 PM Robin Kohrs wrote: Hi everyone:) I'm really sorry for this naive question. I'm kind of starting with GRASS and I just can't find a solution... The issue is, that I would like to try to write a little GRASS Add-on and use the python-fmask package. While this package is only downloadable via conda it always installs into `/home/user/miniconda3/bin/python3`. Even when I did `conda deactivate` prior to this. I guess that mixing conda packages and "regular" ones is causing troubles. When I then have the import statement `import fask` in the grass-script it always throws an error, saying that fmask is not installed. When I print the `sys.executable` in the grass-script it tells me that the interpreter is in `usr/bin/python3`. So I thought that I'd install the fmask-package in a way that this interpreter can find it while executing the script. But I just don't know how. I can add the fmask-path to sys.path, but I don't think this is the solution. Maybe someone has a pointer what I'm not getting. There is also the environment variable PYTHONPATH which could be set in the session. But again, mixing might cause problems. Now I wanted to check http://pythonfmask.org/en/latest/#downloads but the server is down... Hope everyone is good these days:)! Good luck everyone, Markus ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Robin, You could try setting the GRASS_PYTHON environment variable to your Python installation with fmask. import os os.environ['GRASS_PYTHON'] = '/YOUR/PYTHON/PATH' As Markus indicates that can cause other issues. You may also have a look at https://github.com/zarch/grass-session for inspiration. Hope that gives you at least a lead... Cheers Stefan -Original Message- From: grass-user On Behalf Of Robin Kohrs Sent: tirsdag 31. mars 2020 09:25 To: Markus Neteler Cc: GRASS user list Subject: Re: [GRASS-user] Install package for add-on in /usr/bin/python3 Hi Markus, thank you very much for your answer and the help! Do you have any idea what I could do to make the fmask-package "locatable" for the python-interpreter that grass is using? I tried the following options, but I guess I just don't know sufficiently about how python and grass really work together: My python-script looks more or less like this: --- #!/usr/bin/env python3 import sys print("SYS PATH") print(sys.path) print("") print("SYS EXECUTABLE") print(sys.executable) import grass.script as grass from rios import fileinfo # that's where it fails from fmask import fmask --- That's why I tried until now: - I created an environment with conda and installed python-fmask via "conda install -c conda-forge python-fmask". The function "fmask_sentinel2Stacked.py" lies in "/home/robin/miniconda3/bin/fmask_sentinel2Stacked.py". - When I open an interactive python-shell and import fmask and rios and the type: "fmask.__file__" it gives me "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/fmask/__init__.py" - I then added "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/" to the variable PYTHONPATH in my .bashrc - When I now start the interpreter that grass uses from the command line by typing "/usr/bin/pyton3" I can import fmask and rios - However when I run the script with grass it always says that there is no package names rios. Moreover the path I added to PYTHONPATH is not printed when it executes "sys.path" in my grass script I'm sorry for this little confusing question. But in case someone has any idea how I could make grass find fmask, would be super highly appreciated:) thanks a lot in advance! Cheers Robin Citando Markus Neteler : > Hi Robin, > > On Sat, Mar 21, 2020 at 6:15 PM Robin Kohrs wrote: >> >> >> Hi everyone:) >> I'm really sorry for this naive question. I'm kind of starting with >> GRASS and I just can't find a solution... >> The issue is, that I would like to try to write a little GRASS Add-on >> and use the python-fmask package. While this package is only >> downloadable via conda it always installs into >> `/home/user/miniconda3/bin/python3`. Even when I did `conda >> deactivate` prior to this. > > I guess that mixing conda packages and "regular" ones is causing troubles. > >> When I then have the import statement `import fask` in the >> grass-script it always throws an error, saying that fmask is not >> installed. When I print the `sys.executable` in the grass-script it >> tells me that the interpreter is in `usr/bin/python3`. So I thought >> that I'd install the fmask-package in a way that this interpreter can >> find it while executing the script. But I just don't know how. I can >> add the fmask-path to sys.path, but I don't think this is the >> solution. Maybe someone has a pointer what I'm not getting. > > There is also the environment variable PYTHONPATH which could be set > in the session. > But again, mixing might cause problems. > > Now I wanted to check > http://pythonfmask.org/en/latest/#downloads > but the server is down... > >> Hope everyone is good these days:)! > > Good luck everyone, > > Markus ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Markus, thank you very much for your answer and the help! Do you have any idea what I could do to make the fmask-package "locatable" for the python-interpreter that grass is using? I tried the following options, but I guess I just don't know sufficiently about how python and grass really work together: My python-script looks more or less like this: --- #!/usr/bin/env python3 import sys print("SYS PATH") print(sys.path) print("") print("SYS EXECUTABLE") print(sys.executable) import grass.script as grass from rios import fileinfo # that's where it fails from fmask import fmask --- That's why I tried until now: - I created an environment with conda and installed python-fmask via "conda install -c conda-forge python-fmask". The function "fmask_sentinel2Stacked.py" lies in "/home/robin/miniconda3/bin/fmask_sentinel2Stacked.py". - When I open an interactive python-shell and import fmask and rios and the type: "fmask.__file__" it gives me "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/fmask/__init__.py" - I then added "/home/robin/miniconda3/envs/fmask/lib/python3.7/site-packages/" to the variable PYTHONPATH in my .bashrc - When I now start the interpreter that grass uses from the command line by typing "/usr/bin/pyton3" I can import fmask and rios - However when I run the script with grass it always says that there is no package names rios. Moreover the path I added to PYTHONPATH is not printed when it executes "sys.path" in my grass script I'm sorry for this little confusing question. But in case someone has any idea how I could make grass find fmask, would be super highly appreciated:) thanks a lot in advance! Cheers Robin Citando Markus Neteler : Hi Robin, On Sat, Mar 21, 2020 at 6:15 PM Robin Kohrs wrote: Hi everyone:) I'm really sorry for this naive question. I'm kind of starting with GRASS and I just can't find a solution... The issue is, that I would like to try to write a little GRASS Add-on and use the python-fmask package. While this package is only downloadable via conda it always installs into `/home/user/miniconda3/bin/python3`. Even when I did `conda deactivate` prior to this. I guess that mixing conda packages and "regular" ones is causing troubles. When I then have the import statement `import fask` in the grass-script it always throws an error, saying that fmask is not installed. When I print the `sys.executable` in the grass-script it tells me that the interpreter is in `usr/bin/python3`. So I thought that I'd install the fmask-package in a way that this interpreter can find it while executing the script. But I just don't know how. I can add the fmask-path to sys.path, but I don't think this is the solution. Maybe someone has a pointer what I'm not getting. There is also the environment variable PYTHONPATH which could be set in the session. But again, mixing might cause problems. Now I wanted to check http://pythonfmask.org/en/latest/#downloads but the server is down... Hope everyone is good these days:)! Good luck everyone, Markus ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user
Re: [GRASS-user] Install package for add-on in /usr/bin/python3
Hi Robin, On Sat, Mar 21, 2020 at 6:15 PM Robin Kohrs wrote: > > > Hi everyone:) > I'm really sorry for this naive question. I'm kind of starting with > GRASS and I just can't find a solution... > The issue is, that I would like to try to write a little GRASS Add-on > and use the python-fmask package. While this package is only > downloadable via conda it always installs into > `/home/user/miniconda3/bin/python3`. Even when I did `conda > deactivate` prior to this. I guess that mixing conda packages and "regular" ones is causing troubles. > When I then have the import statement `import fask` in the > grass-script it always throws an error, saying that fmask is not > installed. When I print the `sys.executable` in the grass-script it > tells me that the interpreter is in `usr/bin/python3`. So I thought > that I'd install the fmask-package in a way that this interpreter can > find it while executing the script. But I just don't know how. I can > add the fmask-path to sys.path, but I don't think this is the > solution. Maybe someone has a pointer what I'm not getting. There is also the environment variable PYTHONPATH which could be set in the session. But again, mixing might cause problems. Now I wanted to check http://pythonfmask.org/en/latest/#downloads but the server is down... > Hope everyone is good these days:)! Good luck everyone, Markus ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user
[GRASS-user] Install package for add-on in /usr/bin/python3
Hi everyone:) I'm really sorry for this naive question. I'm kind of starting with GRASS and I just can't find a solution... The issue is, that I would like to try to write a little GRASS Add-on and use the python-fmask package. While this package is only downloadable via conda it always installs into `/home/user/miniconda3/bin/python3`. Even when I did `conda deactivate` prior to this. When I then have the import statement `import fask` in the grass-script it always throws an error, saying that fmask is not installed. When I print the `sys.executable` in the grass-script it tells me that the interpreter is in `usr/bin/python3`. So I thought that I'd install the fmask-package in a way that this interpreter can find it while executing the script. But I just don't know how. I can add the fmask-path to sys.path, but I don't think this is the solution. Maybe someone has a pointer what I'm not getting. Hope everyone is good these days:)! Thank you very much in advance, Robin ___ grass-user mailing list grass-user@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-user