Skip to content

Instantly share code, notes, and snippets.

@nick4rivers
Last active April 20, 2022 20:58
Show Gist options
  • Save nick4rivers/f08bc7c8049061841e7fc164a49a6c9f to your computer and use it in GitHub Desktop.
Save nick4rivers/f08bc7c8049061841e7fc164a49a6c9f to your computer and use it in GitHub Desktop.
My notes for Python, Qt, and QGIS plugin development

PYTHON AND QT NOTES FOR QGIS PLUGIN DEVELOPMENT

My notes for Mac OS Qt and QGIS python plugin development tools on VSCode

Qt DEVELOPMENT VIRTUAL ENV:

NEW

python3 -m venv [my_directory]

ACTIVATE

 source my_venv/bin/activate

PIP INSTALL PACKAGES FOR Qt DEVELOPMENT:

*PyQt framework

pip install PyQt5

For packaging QGIS plugins

pip install pb_tool

maybe this one

pip install PyQtWebEngine

PB_TOOL

Need to add the path to the plugin folder to pb_tool.cfg

plugin_path: /Users/nick/Library/Application Support/QGIS/QGIS3/profiles/test/python/plugins

LAUNCH QT DESIGNER THAT SHIPS WITH QGIS:

Launch from the terminal

FOR LTR

/Applications/QGIS-LTR.app/Contents/MacOS/bin/designer

FOR NEWEST RELEASE

/Applications/QGIS.app/Contents/MacOS/bin/designer

VSCODE PATH SETTINGS

These should be in the .vscode directory, in settings.json

{
    // FROM: https://gist.github.com/NicolaiMogensen/acfd8723720c4761aefef3cdfc2aa55a
    // I like changing colors for my projects. QGIS projects are usually green. 
    "workbench.colorCustomizations": {
      "titleBar.activeForeground": "#000000",
      "titleBar.activeBackground": "#0ff381",
    },
    "terminal.integrated.env.osx": {
      "PYTHONPATH": "${env:QGIS_PATH}/Contents/Resources/python:${env:QGIS_PATH}/Contents/Resources/python/site-packages:${env:QGIS_PATH}/Contents/Resources/python/site-packages/PyQt5",
      "PATH": "${env:PATH}:${env:QGIS_PATH}/Contents/MacOS/bin"
    },
    "python.pythonPath": "${env:QGIS_PATH}/Contents/MacOS/bin/python3.8"
  }

Manual path to the QGIS python install

Can be entered in the interpreter if it is being fickle. Note, that new version of QGIS use python 3.9

/Applications/QGIS.app/Contents/MacOS/bin/python3.8

Compiling images

Use pyrcc to compile resources like images. This should be installed with Qt5.

`pyrcc5 -o resources.py resources.qrc`        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment