[QGIS-Developer] Plugin dependency with binaries: 'best' way to guide user to install?
Aron Gergely
aron.gergely at rasterra.nl
Thu Mar 31 05:09:21 PDT 2022
Hi All,
What would be a good practice to handle 3rd party libs which can't be
shipped together with a plugin?
I am looking for the most user-friendly way and have an idea.
But thought I would bounce it off the collective wisdom here and see if
there are other/better ways.
If we find a 'best' method I could PR an update to the QGIS docs or
PyQGIS cookbook, etc to preserve that knowledge.
Bit of context:
I have a plugin that uses a 3rd party python library which has binaries.
I would like to submit this plugin to the official plugin repository.
According to https://plugins.qgis.org/publish/ it's not allowed to ship
binaries it with the plugin.
In such case the above webpage recommends telling the end user to run
"pip.main(...)" from the python console to install missing libraries.
I thought that's not user friendly and it's a pip hack (pip.main() is
meant to be internal).
Also, I want to handle the missing python module in my plugin
gracefully: check on plugin load if missing, if so, guide user to
resolve, preferably without having them write or copy any commands.
The idea:
Using python's subprocess module from within the plugin to call the pip
CLI, which would install the package the usual pip way. Here's why:
- pip project recommends this way as best practice, warns against the
pip.main()
- user would not need to write or copy-paste commands
- could make this user friendly: wire it in the plugin code to a push
button and build it into a dialog e.g.; if lib is missing on plugin load,
show a QMessageBox and let user open a dialog to resolve. In that
dialog would be the push button to trigger the pip install via subprocess.
How would this play out multi-platform via subprocess, I have no idea of
yet - thought if the idea survived this thread, I'd go find out ;)
Do you think this subprocess + pip is a good idea?
Would it be allowed for plugins in the official repository to behave as
such?
Anyone has other user-friendly ways of doing this?
Best regards,
Aron
More information about the QGIS-Developer
mailing list