[QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?

Benjamin Jakimow benjamin.jakimow at geo.hu-berlin.de
Wed Apr 6 06:17:00 PDT 2022



Hi Aron,

with the EnMAP-Box plugin we are confronted with missing PIP packages 
quite often. Therefore we implemented a "PIP Package Installer" 
(screenshot below, source code here: 
https://bitbucket.org/hu-geomatics/enmap-box/src/develop/enmapbox/dependencycheck.py)

In case of missing admin rights you can use the PIP "--user" argument to 
install packages to the user's home folder

D:\OSGeo4W\bin\python3.EXE -m pip install --user lightgbm

The absolute python executable path can be retrieved with 
"shutil.which('python') "

Greetings,

Benjamin

On 2022-04-06 14:01, Aron Gergely via QGIS-Developer wrote:

> @Pedro:
> Tried it today on Windows w OSGeo QGIS and failed right away. But in a 
> different way:
> 
> If I launch OSGeo QGIS and ask for the python executable's path 
> (sys.executabe), I get 'C:/OSGeo4W/bin/qgis-bin.exe'. which looks like 
> entry point is for QGIS.  So subprocess calls that and a new QGIS 
> window opens.
> 
> Not feeling like tackling this and probably other cases.
> So back to download+including those bins I reckon.
> 
> @Johannes:
> Thank you. Yes realizing that now..
> 
> Cheers,
> Aron
> 
> On 06-04-2022 12:12, Johannes Kröger (WhereGroup) wrote:
> 
> Trying to find a smart way to install Python dependencies for the users 
> that will not potentially not work or even break stuff is a very hard 
> thing(tm). Check out these two QEPs for a lot of discussion and 
> possible approaches:
> 
> https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202
> https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179
> 
> Cheers, Hannes
> 
> Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:
> 
> Hey Aron,
> I did explore that route, but I found out that it would fail when the 
> user did not have administrator rights (or even if QGIS had not been 
> ran as administrator on Windows).  Did you find it to be different?
> 
> Cheers,
> Pedro
> 
> ---- On Wed, 06 Apr 2022 03:28:09 +1000 Aron Gergely 
> <aron.gergely at rasterra.nl> wrote ----
> 
> Thank you, I checked out your plugin - yes that seems also a good way.
> I already had the logic to detect, throw message, guide to dialog, 
> etc... implemented similar to yours.
> 
> But I wanted to let pip manage the actual package, so I went with the 
> subprocess+pip route. Here is a minimum working example:
> 
> import subprocess
> import sys
> 
> try:
> subprocess.check_call((sys.executable, '-m', 'pip', 'install', 
> 'h3<=3.99'))
> except subprocess.CalledProcessError as e:
> raise e  # handle any errors here instead
> 
> I connected it to a button in a dialog. And catch stdout, stderr and 
> the exit code of the subprocess so I can show the user what is 
> happening.
> 
> Have not yet tried on other platforms than Linux. But sys.executable is 
> there to solve the ambiguity of python executable path.
> 
> Best regards,
> Aron

-- 
Johannes Kröger / GIS-Entwickler/-Berater

---------------------------------------------
Schon gewusst?

In unserem Blog geben wir Tipps & Tricks zu Open-Source-GIS-Software
und berichten aus unserem Experten-Alltag:
https://wheregroup.com/blog/
---------------------------------------------

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

Tel: +49 (0)228 / 90 90 38 - 36
Fax: +49 (0)228 / 90 90 38 - 11

johannes.kroeger at wheregroup.com
www.wheregroup.com [1]
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
-------------------------------

-- 
Kind Regards,

Aron Gergely
+31 (0) 6 38 70 97 66

Rasterra | www.rasterra.nl [2]

_______________________________________________
QGIS-Developer mailing list
QGIS-Developer at lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

-- 
--
Benjamin Jakimow, Doctoral Researcher
Earth Observation Lab | Geography Department | Humboldt-Universität zu 
Berlin

e-mail: benjamin.jakimow at geo.hu-berlin.de

phone:  +49 (0) 30 2093 6894
mobile: +49 (0) 157 5656 8477
fax:    +49 (0) 30 2093 6848
mail:   Unter den Linden 6 | 10099 Berlin | Germany
room: 2'222

Links:
------
[1] http://www.wheregroup.com
[2] http://www.rasterra.nl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220406/0572bf39/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 51d6a740.png
Type: image/png
Size: 56151 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20220406/0572bf39/attachment-0001.png>


More information about the QGIS-Developer mailing list