[QGIS-Developer] External python package dependency in plugins

Richard Duivenvoorde rdmailings at duif.net
Sat Jul 7 02:45:28 PDT 2018


On 07/07/2018 08:11 AM, shiva reddy wrote:
>     Hello,
>     I tried to install automatically during my pluign (QRealTime)
>     installation by calling:
> 
>      subprocess.call(['python','-m','install','pyxform','--user'])
> 
>     It worked many times in windows and it fails sometime.
>     It don't work in OS X and I have not tested in ubuntu.
> 
>     What is the best practice for such situation?

Hi, I tried your lines here on Debian 9.4/testing/ in a python3 console:

>>> import subprocess
>>> subprocess.call(['python','-m','install','pyxform','--user'])
/usr/bin/python: No module named install
1
>>> subprocess.call(['python','-m','pip','install','pyxform','--user'])
/usr/bin/python: No module named pip
1

Ah, but with Debian we have python and python 3, so I tried:
subprocess.call(['python3','-m','pip','install','pyxform','--user'])
...
Installing collected packages: argparse, linecache2, traceback2, six,
unittest2, formencode, unicodecsv, xlrd, pyxform
Successfully installed argparse-1.4.0 formencode-1.3.1 linecache2-1.0.0
pyxform-0.11.3 six-1.11.0 traceback2-1.4.0 unicodecsv-0.14.1
unittest2-1.1.0 xlrd-1.1.0
0
Works! \o/
Not sure if (from within python) you can find out what the name of the
python executable is...

For QGIS2 we earlier recommended to just add the full module into your
plugin package. (if possible, aka python-only module).

There has also been discussion about using pip for python modules, by
adding the 'pip install line' as a separate metadata.txt line.
In that way we could either let users install it (in their global or
user env), or maybe later do this programatically.

There are questions/discussions/options:
- how to handle clashing specific versions of the same module between
different plugins
- where to install modules: installation system wide, in one QGIS
virtual environment (venv) or in a venv per plugin
- security questions (mostly a Linux discussion: should a distribution
rely on venv's or only install distribution modules)... etc

Your idea is (to me) new :-)
If working platform independently and full proof, I think it is an
interesting option!

Now with QGIS3 we have true separated profiles, we an idea would be to
add a virtual environment PER profile, so all plugins can install
modules in that environment (using your trick?), and in case of a clash
can then create 2 profiles for those plugins/modules.
Not sure though this is feasible for all OS's. I think it will be
easiest on Linux...

Others?

Regards,

Richard Duivenvoorde


More information about the QGIS-Developer mailing list