<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style='font-size: 10pt; font-family: Verdana,Geneva,sans-serif'>
<p id="reply-intro">Hi Aron,</p>
<p>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: <a href="https://bitbucket.org/hu-geomatics/enmap-box/src/develop/enmapbox/dependencycheck.py">https://bitbucket.org/hu-geomatics/enmap-box/src/develop/enmapbox/dependencycheck.py</a>)</p>
<p>In case of missing admin rights you can use the PIP "--user" argument to install packages to the user's home folder</p>
<p>D:\OSGeo4W\bin\python3.EXE -m pip install --user lightgbm</p>
<p>The absolute python executable path can be retrieved with "shutil.which('python') "</p>
<p><br /></p>
<p><img src="cid:51d6a740d0ed29035fc8adb0941e653a@geo.hu-berlin.de" /></p>
<p><br /></p>
<p>Greetings,</p>
<p>Benjamin</p>
<p>On 2022-04-06 14:01, Aron Gergely via QGIS-Developer wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div id="replybody1">
<div>
<p>@Pedro:<br />Tried it today on Windows w OSGeo QGIS and failed right away. But in a different way:<br /><br />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.<br /><br />Not feeling like tackling this and probably other cases.<br />So back to download+including those bins I reckon.<br /><br />@Johannes:<br />Thank you. Yes realizing that now..<br /><br /><br />Cheers,<br />Aron<br /><br /><br /><br /></p>
<div class="v1moz-cite-prefix">On 06-04-2022 12:12, Johannes Kröger (WhereGroup) wrote:</div>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<p>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:<br /><br /><a class="v1moz-txt-link-freetext" href="https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202" target="_blank" rel="noopener noreferrer">https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202</a><br /><a class="v1moz-txt-link-freetext" href="https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179" target="_blank" rel="noopener noreferrer">https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179</a></p>
<p>Cheers, Hannes</p>
<div class="v1moz-cite-prefix">Am 06.04.22 um 00:10 schrieb Pedro Camargo via QGIS-Developer:</div>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; margin: 0">
<div style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt;">
<div>Hey Aron,</div>
<div>                   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?</div>
<div> </div>
<div>Cheers,</div>
<div>Pedro</div>
<div> </div>
<div> </div>
<div class="v1zmail_extra">
<div> </div>
<div id="v1Zm-_Id_-Sgn1">---- On Wed, 06 Apr 2022 03:28:09 +1000 <strong>Aron Gergely <a class="v1moz-txt-link-rfc2396E" href="mailto:aron.gergely@rasterra.nl" rel="noreferrer"><aron.gergely@rasterra.nl></a></strong> wrote ----</div>
<div> </div>
<blockquote style="border-left: 1px solid #cccccc; padding-left: 6px; margin: 0px 0px 0px 5px;">
<div>
<p>Thank you, I checked out your plugin - yes that seems also a good way.<br />I already had the logic to detect, throw message, guide to dialog, etc... implemented similar to yours.<br /><br />But I wanted to let pip manage the actual package, so I went with the subprocess+pip route. Here is a minimum working example:</p>
<pre style="background-color: #2b2b2b; color: #a9b7c6; font-family: 'JetBrains Mono', monospace; font-size: 9.8pt;"><span class="v1colour" style="color: #cc7832;">import </span>subprocess
<span class="v1colour" style="color: #cc7832;">import </span>sys


<span class="v1colour" style="color: #cc7832;">try</span>:
    subprocess.check_call((sys.executable<span class="v1colour" style="color: #cc7832;">, </span><span class="v1colour" style="color: #6a8759;">'-m'</span><span class="v1colour" style="color: #cc7832;">, </span><span class="v1colour" style="color: #6a8759;">'pip'</span><span class="v1colour" style="color: #cc7832;">, </span><span class="v1colour" style="color: #6a8759;">'install'</span><span class="v1colour" style="color: #cc7832;">, </span><span class="v1colour" style="color: #6a8759;">'h3<=3.99'</span>))
<span class="v1colour" style="color: #cc7832;">except </span>subprocess.CalledProcessError <span class="v1colour" style="color: #cc7832;">as </span>e:
    <span class="v1colour" style="color: #cc7832;">raise </span>e  <span class="v1colour" style="color: #808080;"># handle any errors here instead</span>

</pre>
<p>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.<br /><br />Have not yet tried on other platforms than Linux. But sys.executable is there to solve the ambiguity of python executable path.<br /><br /><br />Best regards,<br />Aron<br /><br /><br /></p>
</div>
</blockquote>
</div>
</div>
</blockquote>
<pre class="v1moz-signature">-- 
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:
<a class="v1moz-txt-link-freetext" href="https://wheregroup.com/blog/" target="_blank" rel="noopener noreferrer">https://wheregroup.com/blog/</a>
---------------------------------------------

WhereGroup GmbH
Grevenweg 89
20537 Hamburg
Germany

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

<a class="v1moz-txt-link-abbreviated v1moz-txt-link-freetext" href="mailto:johannes.kroeger@wheregroup.com" rel="noreferrer">johannes.kroeger@wheregroup.com</a>
<a class="v1moz-txt-link-abbreviated" href="http://www.wheregroup.com" target="_blank" rel="noopener noreferrer">www.wheregroup.com</a>
Geschäftsführer:
Olaf Knopp, Peter Stamm 
Amtsgericht Bonn, HRB 9885
-------------------------------
</pre>
</blockquote>
<div class="v1moz-signature">-- <br />Kind Regards,<br /><br />Aron Gergely<br />+31 (0) 6 38 70 97 66<br /><br /><strong>Rasterra</strong> | <a class="v1moz-txt-link-abbreviated" href="http://www.rasterra.nl" target="_blank" rel="noopener noreferrer">www.rasterra.nl</a><a><br /></a></div>
</div>
</div>
<br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">_______________________________________________<br />QGIS-Developer mailing list<br /><a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br />List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br />Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank" rel="noopener noreferrer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a></div>
</blockquote>
<p><br /></p>
<div id="signature">-- <br />
<div class="pre" style="margin: 0; padding: 0; font-family: monospace">--<br />Benjamin Jakimow, Doctoral Researcher<br />Earth Observation Lab | Geography Department | Humboldt-Universität zu Berlin<br /><br />e-mail: <a href="mailto:benjamin.jakimow@geo.hu-berlin.de">benjamin.jakimow@geo.hu-berlin.de</a><br /><br />phone:  +49 (0) 30 2093 6894<br />mobile: +49 (0) 157 5656 8477<br />fax:    +49 (0) 30 2093 6848<br />mail:   Unter den Linden 6 | 10099 Berlin | Germany<br />room: 2'222</div>
</div>
</body></html>