6

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

4

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=
2
3

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)
2
  • 3
    While 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
    Commented 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
    Commented Mar 30, 2020 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.