<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <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="moz-txt-link-freetext" href="https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202">https://github.com/qgis/QGIS-Enhancement-Proposals/issues/202</a><br>
      <a class="moz-txt-link-freetext" href="https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179">https://github.com/qgis/QGIS-Enhancement-Proposals/issues/179</a></p>
    <p>Cheers, Hannes<br>
    </p>
    <div class="moz-cite-prefix">Am 06.04.22 um 00:10 schrieb Pedro
      Camargo via QGIS-Developer:<br>
    </div>
    <blockquote type="cite"
      cite="mid:17ffbc72799.86c43b9f23292.7962298494395626212@margo.co">
      <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
      <div style="font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 10pt;">
        <div>Hey Aron,<br>
        </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?<br>
        </div>
        <div><br>
        </div>
        <div>Cheers,<br>
        </div>
        <div>Pedro<br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div class="zmail_extra" data-zbluepencil-ignore="true">
          <div><br>
          </div>
          <div id="Zm-_Id_-Sgn1">---- On Wed, 06 Apr 2022 03:28:09 +1000
            <b>Aron Gergely <a class="moz-txt-link-rfc2396E" href="mailto:aron.gergely@rasterra.nl"><aron.gergely@rasterra.nl></a></b> wrote
            ----<br>
          </div>
          <div><br>
          </div>
          <blockquote style="border-left: 1px solid rgb(204, 204, 204);
            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:<br>
              </p>
              <pre style="background-color: rgb(43,43,43);color: rgb(169,183,198);font-family: "JetBrains Mono", monospace;font-size: 9.8pt;"><span class="colour" style="color:rgb(204, 120, 50)">import </span>subprocess
<span class="colour" style="color:rgb(204, 120, 50)">import </span>sys


<span class="colour" style="color:rgb(204, 120, 50)">try</span>:
    subprocess.check_call((sys.executable<span class="colour" style="color:rgb(204, 120, 50)">, </span><span class="colour" style="color:rgb(106, 135, 89)">'-m'</span><span class="colour" style="color:rgb(204, 120, 50)">, </span><span class="colour" style="color:rgb(106, 135, 89)">'pip'</span><span class="colour" style="color:rgb(204, 120, 50)">, </span><span class="colour" style="color:rgb(106, 135, 89)">'install'</span><span class="colour" style="color:rgb(204, 120, 50)">, </span><span class="colour" style="color:rgb(106, 135, 89)">'h3<=3.99'</span>))
<span class="colour" style="color:rgb(204, 120, 50)">except </span>subprocess.CalledProcessError <span class="colour" style="color:rgb(204, 120, 50)">as </span>e:
    <span class="colour" style="color:rgb(204, 120, 50)">raise </span>e  <span class="colour" style="color:rgb(128, 128, 128)"># 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="moz-signature" cols="72">-- 
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="moz-txt-link-freetext" href="https://wheregroup.com/blog/">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="moz-txt-link-abbreviated" href="mailto:johannes.kroeger@wheregroup.com">johannes.kroeger@wheregroup.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.wheregroup.com">www.wheregroup.com</a>
Geschäftsführer:
Olaf Knopp, Peter Stamm 
Amtsgericht Bonn, HRB 9885
-------------------------------
</pre>
  </body>
</html>