Build the plugin

Important

Make sure, where is the PyQt5 resource compiler (pyrcc5) available in your PATH

You can test it by running

pyrcc5 -help

You should obtain readable help message

_images/pyrcc5-help.png

Note

If you are on MS Windows, open OSGeo4W Shell:

_images/pyrcc5-windows.png

To build the plugin pb_tool must be available in the system. This package is available via PyPI service.

Note

It might look as good idea to use standard make, since Makefile is available too. This is considered deprecated option and should no longer be used. pb_tool is more complex build system (and supports various operating systems).

To install pb_tool run the command below (on MS Windows use OSGeo4W Shell):

python3 -m pip install pb_tool

Configuration file pb_tool.cfg

pb_tool needs a configuration file (generated by the Plugin Builder). In this file, you can modify target plugin path as well as locales, extra directories needed and other metadata.

Using plugin in place

Instead of deploying the plugin using pb_tool it is more flexible when the plugin to set up by QGIS environment in order to be able to install the plugin from current folder without need of deployment.

Let’s add your plugin location to the QGIS_PLUGINPATH in Settings ‣ Options ‣ System. Enable Use custom variables in Environment section and add a new variable: QGIS_PLUGINPATH. This variable should point to a parent directory where the plugin is located. Restart (close and open) QGIS and continue with installing the plugin.

Important

QGIS doesn’t allow in the path defined by QGIS_PLUGINPATH non-ascii characters. If your path contains such characters than consider to rename directories in the path which causing this issue.

_images/qgis-pluginpath.svg

Fig. 12 Setting of the QGIS_PLUGINPATH variable.

Activate plugin in QGIS

Open QGIS and find the new plugin in the Plugins ‣ Manage and Install Plugins…. Check the checkbox to activate the plugin in QGIS.

_images/save-views-enable.png

Fig. 13 Activate plugin Save Views.

An icon of the plugin new_plugin appears in the toolbar as well as new menu selection in Vector ‣ Save Views ‣ Save Views.

When running it, a new (empty) dialog will be open.

_images/plugin-ui-template.png

Notes

Virtualenv

Virtualenv is one of the possibilities, how to keep your code and it’s dependencies independent.

To create the virtualenv, run

python3 -m venv myvenv

For QGIS running within Python virtualenv, you need to adjust activate script and add PYTHONPATH with Python, Qt and QGIS libraries.

$EDITOR myvenv/bin/activate

[...]
export PYTHONPATH=$PYTHONPATH:/usr/local/share/qgis/python/:/usr/lib/python3/dist-packages/
[...]

To initialize the virtualenv, run

source myenv/bin/activate

Note

It’s generally good advice to use virtualenvwrapper tool.