<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello John,</p>
    <p><br>
    </p>
    <p>It's a recurring issue/question since QGIS does not support pip
      dependencies and that PyQGIS plugins are not following the
      official Python packaging standards from PEPs and related formats
      (typically metadata.txt instead of setup.cfg, pyproject.toml). You
      will find some unsuccessful QEPs about this. For example:
      <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>.</p>
    <p><br>
    </p>
    <p>Shortly, here come 3 workarounds:</p>
    <ul>
      <li>basic: run pip install in a rough subcommand. Not so elegant
        but still efficient.</li>
      <li>re-wheeling: implement a minimalist (or complete) 3rd party
        packages managers, miming pip through QgsNetwork tooling. Best
        example I know until today: ENMap-Box plugin (see attached
        screenshot or try it yourself).</li>
      <li>YAML addicts: run your pip install during your plugin's
        packaging job in CI and include external dependencies in a
        subfolder before deploying it to your favorite plugins
        repository. Then, manage install loading from your plugin with
        try/except ImportError and 'site' module. This is the way I
        prefer and use for years now. Main downside: for dependencies
        requiring a specific compilation on an operating system, you
        need to include various outputs. See <a
          href="https://github.com/DINFO-UniFI/RoofClassify">Roof
          Classify</a> (GitHub Workflow), <a
          href="https://gitlab.com/Oslandia/qgis/thyrsis">Thyrsis</a>
        (GitLab CI), <a
          href="https://gitlab.com/Oslandia/qgis/QSoccer/">QSoccer</a>
        (GitLab CI), <a href="https://gitlab.com/Oslandia/qgis/qduckdb">QDuckDB</a>
        (GitLab CI)... If you're interested, let me know. It could
        motivate me to write a tutorial detailing this method.<br>
      </li>
      <li>bravehearts: working on packaging your dependencies into
        osgeo4w; but they probably won't be included in default QGIS
        packages (.msi)<br>
      </li>
    </ul>
    <p>Just a quick advice: if you do some pip install within your
      plugin, during the packaging or during the run, make it under a
      custom folder related only to your plugin and use site to load
      extra dependencies in the QGIS Python environment to avoid issues.<br>
    </p>
    <p><br>
    </p>
    <p>Good luck!</p>
    <p>Regards</p>
    <p>Julien<br>
    </p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Le 19/01/2024 à 16:00, John Lindsay via
      QGIS-Developer a écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:YQBPR0101MB4242A832B53713D30AE228A0C1702@YQBPR0101MB4242.CANPRD01.PROD.OUTLOOK.COM">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <div class="elementToProof"><span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">Hello
          everyone,</span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div class="elementToProof"
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">I
          am developing a new QGIS plugin (</span><span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><a
href="https://plugins.qgis.org/plugins/whitebox_workflows_for_qgis/#plugin-manage"
            id="LPlnk167391" moz-do-not-send="true"
            class="moz-txt-link-freetext">https://plugins.qgis.org/plugins/whitebox_workflows_for_qgis/#plugin-manage</a></span><span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">)
          that serves as a frontend for a Python geospatial analysis
          library called Whitebox Workflows for Python (WbW). The plugin
          seems to work well with on major exception, it requires that
          the user have WbW installed. It can be installed quite easily
          using pip (pip install whitebox-workflows), however, I know
          that QGIS uses its own localized version of Python, which
          seems to lack a terminal app access (at least on MacOS).
          Besides, a better solution would be for the plugin to install
          this package via pip when it is itself first installed and
          launched. I tried to accomplish this with the following code:</span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><a
href="https://github.com/jblindsay/whitebox_workflows_for_qgis/blob/4e463262f6cfd1987afa2f3f7e0e79656eb8d27e/whitebox_workflows_for_qgis_provider.py#L56"
            target="_blank" id="OWAd2690c2b-c8d5-4324-b0d7-a2434bc6158d"
            class="OWAAutoLink moz-txt-link-freetext"
            rel="noopener noreferrer" data-auth="NotApplicable"
            data-linkindex="0" style="margin: 0px;"
            moz-do-not-send="true">https://github.com/jblindsay/whitebox_workflows_for_qgis/blob/4e463262f6cfd1987afa2f3f7e0e79656eb8d27e/whitebox_workflows_for_qgis_provider.py#L56</a></span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 15px; color: rgb(36, 36, 36); font-weight: 400;"><br>
        </span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">This
          code, which runs whenever the plugin is launched, first checks
          to see if whitebox_workflows can be imported and if not, it
          runs pip from the Python script to install it. Unfortunately,
          some users have reported issues with this not working
          correctly:</span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><a
href="https://github.com/jblindsay/whitebox_workflows_for_qgis/issues/1"
            target="_blank" id="OWA45fa6a2e-fb7f-1e7b-50bb-9534f5e16eb5"
            class="OWAAutoLink moz-txt-link-freetext"
            rel="noopener noreferrer" data-auth="NotApplicable"
            data-linkindex="1" style="margin: 0px;"
            moz-do-not-send="true">https://github.com/jblindsay/whitebox_workflows_for_qgis/issues/1</a></span></div>
      <div style="background-color: rgb(255, 255, 255); margin: 0px;">
        <div
          style="margin: 16px 0px; max-width: 800px; min-width: 424px;">
          <div style="margin: 0px; height: 116px;">
            <div style="text-align: left; margin: 0px;"><span
style="letter-spacing: normal; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 15px; color: rgb(36, 36, 36); font-weight: 400;">
                <button type="button"
                  class="ms-Button ms-Button--icon wD8TJ root-685"
                  title="Show original size" data-is-focusable="true"
style="border:none;font-size:16px;font-family:controlIcons !important;margin:0px;padding:8px;outline:transparent;border-radius:2px;box-sizing:border-box;cursor:pointer;display:inline-block;text-decoration:none;text-align:center;width:32px;height:32px;user-select:none;box-shadow:0 0 5px var(--neutralSecondary);left:5px;top:5px;z-index:1">
                  <div
style="text-align: left; line-height: 16px; margin: 0px 4px; height: 16px; display: inline-block;">
                    <span style="font-family: controlIcons;"></span></div>
                </button></span></div>
            <table id="LPContainer627363"
style="text-align: left; border-width: 1px; border-style: solid; border-color: rgb(200, 200, 200); border-radius: 2px; width: 1004.07px;">
              <tbody>
                <tr>
                  <td style="text-align: left;">
                    <div
style="text-align: left; margin: 0px 12px 0px 0px; height: 120px;"><span
style="letter-spacing: normal; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 15px; color: rgb(36, 36, 36); font-weight: 400;"><a
href="https://github.com/jblindsay/whitebox_workflows_for_qgis/issues/1"
                          target="_blank" id="LPImageAnchor627363"
                          rel="noopener noreferrer"
                          data-auth="NotApplicable" data-linkindex="2"
                          style="margin: 0px;" moz-do-not-send="true"><img
                            id="LPThumbnailImageId627363"
style="width: 240px; height: 120px; margin: 0px; display: block;"
src="https://opengraph.githubassets.com/a248a1a51b43baa531f4fdf47f85868a01c5785c3dded22234ce269d2c64c9e4/jblindsay/whitebox_workflows_for_qgis/issues/1"
                            moz-do-not-send="true" width="240"
                            height="120"></a></span></div>
                  </td>
                  <td style="text-align: left; width: 692.07px;">
                    <div
style="text-align: left; margin: 0px 8px 12px 0px;"><span
style="letter-spacing: normal; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 21px; color: rgb(36, 36, 36); font-weight: 300;"><a
href="https://github.com/jblindsay/whitebox_workflows_for_qgis/issues/1"
                          target="_blank" id="LPUrlAnchor627363"
                          rel="noopener noreferrer"
                          data-auth="NotApplicable" data-linkindex="3"
                          style="text-decoration: none; margin: 0px;"
                          moz-do-not-send="true">Installation in QGis
                          fails · Issue #1 ·
                          jblindsay/whitebox_workflows_for_qgis</a></span></div>
                    <div
style="text-align: left; margin: 0px 8px 12px 0px; max-height: 100px;"><span
style="letter-spacing: normal; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; color: rgb(102, 102, 102); font-weight: 400;">AttributeError:
                        'NoneType' object has no attribute 'write'
                        Traceback (most recent call last): File
"<a class="moz-txt-link-freetext" href="C:\\Users/thomas.struller/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins\\whitebox_work">C:\\Users/thomas.struller/AppData/Roaming/QGIS/QGIS3\\profiles\\default/python/plugins\\whitebox_work</a>...</span></div>
                    <div
style="text-align: left; margin: 0px; font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; font-size: 14px; color: rgb(166, 166, 166);">
                      <span
style="letter-spacing: normal; font-weight: 400;">github.com</span></div>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">So
          now I'm left trying to figure out what the recommended
          approach to installing QGIS plugin dependencies is. Any advice
          from anyone that has successfully dealt with this problem
          previously? Thanks.</span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">Regards,</span></div>
      <div
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;"><br>
        </span></div>
      <div class="elementToProof"
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0px;">
        <span
style="letter-spacing: normal; font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); font-weight: 400;">John
          Lindsay</span></div>
      <div class="elementToProof"
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
        <br>
      </div>
      <div id="Signature">
        <div
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
          <br>
        </div>
        <div id="divtagdefaultwrapper" dir="ltr"
style="font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
          <p style="margin-top: 0px; margin-bottom: 0px;">Prof. John
            Lindsay</p>
          <p
style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif;">
            <span style="font-size: 12pt; color: rgb(0, 0, 0);">Dept. of
              Geography, Environment & Geomatics,</span></p>
          <p
style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif;">
            The University of Guelph,</p>
          <p
style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif;">
            Room 122, Hutt Building,</p>
          <p style="margin-top: 0px; margin-bottom: 0px;"><span
style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">E-mail:
              <a class="moz-txt-link-abbreviated" href="mailto:jlindsay@uoguelph.ca">jlindsay@uoguelph.ca</a></span></p>
          <p style="margin-top: 0px; margin-bottom: 0px;">Phone: (519)
            824-4120 ext. 56074</p>
          <p style="margin-top: 0px; margin-bottom: 0px;">Web: <a
              href="https://geg.uoguelph.ca/faculty/lindsay-john"
              style="margin-top: 0px; margin-bottom: 0px;"
              moz-do-not-send="true" class="moz-txt-link-freetext">
              https://geg.uoguelph.ca/faculty/lindsay-john</a></p>
          <p style="margin-top: 0px; margin-bottom: 0px;">Research page:
            <a href="https://jblindsay.github.io/ghrg/index.html"
              title="https://jblindsay.github.io/ghrg/index.html"
              style="margin-top: 0px; margin-bottom: 0px;"
              moz-do-not-send="true" class="moz-txt-link-freetext">
              https://jblindsay.github.io/ghrg/index.html</a></p>
          <p style="margin-top: 0px; margin-bottom: 0px;"><span
style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">WhiteboxTools
              GIS project:
              <a href="https://www.whiteboxgeo.com/"
                style="margin-top: 0px; margin-bottom: 0px;"
                moz-do-not-send="true" class="moz-txt-link-freetext">
                https://www.whiteboxgeo.com/</a></span></p>
          <p style="margin-top: 0px; margin-bottom: 0px;"><span
style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">Twitter:
              <a href="https://twitter.com/whiteboxgeo"
                style="margin-top: 0px; margin-bottom: 0px;"
                moz-do-not-send="true" class="moz-txt-link-freetext">
                https://twitter.com/whiteboxgeo</a></span><br>
          </p>
        </div>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
    </blockquote>
  </body>
</html>