I am looking for a way to install and activate plugins in QGIS without accessing the GUI. I have a QGIS instance running on a remote server where I run standalone Python scripts that process the data.
I would like to install a couple of plugins so that I can run their algorithms using processing.run()
. Either a command line or from Python script solution would work for me.
I had no luck searching through the documentation.
Any suggestions?
2 Answers 2
IMO best way to install QGIS plugin is qgis-plugin-manager. This is usage example:
pip3 install qgis-plugin-manager
mkdir -p ~/.local/share/QGIS/QGIS3/profiles/default/python/plugins
cd ~/.local/share/QGIS/QGIS3/profiles/default/python/plugins
qgis-plugin-manager init
qgis-plugin-manager update
qgis-plugin-manager install "your_plugin_name"
And then maybe you need to activate plugin. To do this, you should find in file ~/.local/share/QGIS/QGIS3/profiles/default/QGIS/QGIS3.ini
line [PythonPlugins]
and enable your plugin below, for example:
[PythonPlugins]
your_plugin_name=true
If you don't know exact your plugin name, you can find it after installation on a line starting with:
plugin_installer\seen_plugins=
-
You need to fix
qgis-plugin-master
byqgis-plugin-manager
. The link to the documentation of QGIS-Plugin-Manager : github.com/3liz/qgis-plugin-manageretrimaille– etrimaille2022年08月03日 09:53:34 +00:00Commented Aug 3, 2022 at 9:53 -
I just edited your answer. Note for QGIS Server, plugins doesn't need to be activated in your
ini
file. Link to the documentation about installing plugins on a server docs.qgis.org/3.22/en/docs/server_manual/…etrimaille– etrimaille2022年08月03日 09:56:22 +00:00Commented Aug 3, 2022 at 9:56
For testing an approach, I arbitrarily chose "Append Features to Layer" and, with its link from plugins repository of QGIS:
https://plugins.qgis.org/plugins/AppendFeaturesToLayer/version/1.0.0/download/
by using following ariac command (aria package was previously installed in my GNU/Linux Debian):
aria2c -d /home/zeito/.local/share/QGIS/QGIS3/profiles/default/python/plugins https://plugins.qgis.org/plugins/AppendFeaturesToLayer/version/1.0.0/download/
it was successfully downloaded in plugin folder:
~/.local/share/QGIS/QGIS3/profiles/default/python/plugins
of my QGIS 3.12.1 as AppendFeaturesToLayer-1.0.0.zip. With command lines, I can unpack this zip file and run make, in plugin folder, for activating it before launching QGIS. So, I think it is possible to create a bash script for all process (downloading, unpacking and activating) for whatever plugin.
Editing Note:
With Python it was also possible. It's just a matter of making interactive following script.
from os import system
qgis_plugin_path = "/home/zeito/.local/share/QGIS/QGIS3/profiles/default/python/plugins"
qgis_plugin_repository = "https://plugins.qgis.org/plugins/AppendFeaturesToLayer/version/1.0.0/download/"
cmd = "aria2c -d " + qgis_plugin_path + " " + qgis_plugin_repository
system(cmd)
-
3While this approach is something that works, you need to know a lot besides the name of the plugin (i.e. current version) to get the correct link to download the file. I was wondering if there is a way to do something like
QgsApplication.installPlugin("plugin_name)
.Jan Caha– Jan Caha2020年03月30日 14:40:27 +00:00Commented Mar 30, 2020 at 14:40 -
Only methods in QgsApplication with prefix 'install' are 'installEventFilter', 'installNativeEventFilter' and 'installTranslator'. You can search each one function.xunilk– xunilk2020年03月30日 14:58:57 +00:00Commented Mar 30, 2020 at 14:58