Is it possible to install QGIS Plugins with Python code?
I would like to be able to provide users who have a basic QGIS image served up to them, to be able to quickly install all their required plugins with a tailored Python script to save them manually installing each via the usual menu route, one at a time.
I cannot see any code that runs in logs after a successful plugin install and no clues online in my searches.
1 Answer 1
The answer is yes.
Installing a plugin from the QGIS Plugins Repository
This is how you can install a plugin called loadthemall
:
import pyplugin_installer
pyplugin_installer.instance().fetchAvailablePlugins(False)
pyplugin_installer.instance().installPlugin('loadthemall')
Plugin keys correspond to their folder names. Some examples: AppendFeaturesToLayer
, asistente_ladm_col
, loadthemall
, profiletool
.
As last resort, you could get plugin keys in this way (if you haven't called fetchAvailablePlugins
, it will give you installed plugin keys):
pyplugin_installer.installer_data.plugins.all().keys()
Installing a plugin from ZIP file
pyplugin_installer.instance().installFromZipFile('/path/to/plugin/file.zip')
Uninstalling a plugin
pyplugin_installer.instance().uninstallPlugin('loadthemall')
Note: This is not a stable API, and might be modified with no backwards compatibility.
-
This fully solves my issues, and this in particular has helped with the issue of how to call the individual Plugins: pyplugin_installer.installer_data.plugins.all().keys()Graeme– Graeme2020年06月29日 08:45:28 +00:00Commented Jun 29, 2020 at 8:45
-
What does this line do? pyplugin_installer.instance().fetchAvailablePlugins(False)ar-siddiqui– ar-siddiqui2021年06月19日 13:19:32 +00:00Commented Jun 19, 2021 at 13:19
-
It goes to internet and fetches data of plugins that QGIS hasn't fetched yet. If you have other repos configured, it will visit those repos as well. See the source for details.Germán Carrillo– Germán Carrillo2021年06月19日 13:39:54 +00:00Commented Jun 19, 2021 at 13:39
Explore related questions
See similar questions with these tags.
pyplugin_installer
instance. Quick example:import pyplugin_installer
|pyplugin_installer.instance().fetchAvailablePlugins(False)
|pyplugin_installer.instance().installPlugin('asistente_ladm_col')
You can read the installer.py code to get some inspiration.