QGIS3 Python plugin development environment construction with VSCode (macOS)

This is a memo when creating an environment for developing and remote debugging QGIS plugins on VSCode. The environment is as follows.

It's not very bright in QGIS or Python, so that's one good thing.

Install QGIS

Install with the installer downloaded from Official Site or Homebrew Cask.

$ brew cask install qgis

I have installed the latest version (Version 3.12.3).

Suddenly try to make a QGIS plugin

Plugin Development of GIS Practice Open Teaching Material Use Plugin Builder 3 to create a test plugin by referring to the materials / python / 10/10.html) page.

The location to export the plugin is the default profile plugin directory (* / Users / username / Library / Application Support / QGIS / QGIS3 / profiles / default / python / plugins *).

At the stage of plug-in generation, an error stating that there is no resource compiler is displayed, but for the time being, it is written out. pyrcc5 error

Install PyQt

Now that you need pyrcc5, install PyQt with Homebrew.

$ brew install pyqt

The dependency requires [email protected], but if the resources of the plugin created earlier can be compiled, it's OK for the time being.

$ cd /Users/xxx/Library/Application\ Support/QGIS/QGIS3/profiles/default/python/plugins/plugin_test
$ pyrcc5 -o resources.py resources.qrc

Activate the created plug-in from the "Plug-in"-> "Plug-in management and installation ..." menu, and check until it can be executed. テストプラグインの起動

Install Python Tools for Visual Studio debug server

I want to install ptvsd, a Python debugger package for VS / VSCode, but I don't have the pip for Python that comes with QGIS ...

So first go to the PyPI ptvsd package page and download * ptvsd-4.3.2.zip * from Download files.

Extract the archive and copy the * ptvsd * folder in * ptvsd-4.3.2 / src * under * / Applications / QGIS3.12.app / Contents / Resources / python *.

$ cd ~/Downloads
$ unzip ptvsd-4.3.2.zip
$ cd ptvsd-4.3.2/src
$ cp -r ptvsd /Applications/QGIS3.12.app/Contents/Resources/python

Restart QGIS and install the debugvs plugin. After installation, select [Enable Debug Visual Studio] from the plugin menu or the button on the toolbar. debugvs

OK if the message "Remote Debug for Visual Studio is running" is displayed. Remote Debug for Visual Studio is running

Remote debugging from VSCode

Start VSCode using the plugin directory you created earlier as a workspace.

$ cd /Users/xxx/Library/Application\ Support/QGIS/QGIS3/profiles/default/python/plugins/plugin_test
$ code .

Specifying Python interpreter

Run Python: Select Interpreter from the command palette Select Interpreter

Select "Enter interpreter path ..." and specify * / Applications / QGIS3.12.app / Contents / MacOS / bin / python3 * directly Enter path

The settings will be written to * .vscode / settings.json *.

settings.json


{
  "python.pythonPath": "/Applications/QGIS3.12.app/Contents/MacOS/bin/python3"
}

Add debug configuration

Select Run> Add Configuration ... menu to add the configuration for remote debugging.

Environment selection: Python Debug Configuration: Remote Attach Enter the host name: localhost Enter the port number that ... (Omitted): 5678

The configuration will be added to * .vscode / launch.json *. If it is left as it is, it will not work well, so modify the value of remoteRoot of pathMappings to "$ {workspaceFolder}".

launch.json


{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python:attach",
      "type": "python",
      "request": "attach",
      "port": 5678,
      "host": "localhost",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "${workspaceFolder}"
        }
      ]
    }
  ]
}

Now when you start debugging with "Run"-> "Start Debugging" etc., it will be attached to the QGIS Python debug server. You can check that debugging is possible by setting a breakpoint in the code and executing the plugin. Break Point

I have a feeling that it will be possible to develop in a familiar environment.

Recommended Posts

QGIS3 Python plugin development environment construction with VSCode (macOS)
Python3 + venv + VSCode + macOS development environment construction
[MEMO] [Development environment construction] Python
Get started with Python! ~ ① Environment construction ~
[Python3] Development environment construction << Windows edition >>
Python3 environment construction with pyenv-virtualenv (CentOS 7.3)
Emacs Python development environment construction memo
pytorch @ python3.8 environment construction with pipenv
Prepare Python development environment with Atom
Create a simple Python development environment with VSCode & Docker Desktop
[Ubuntu 18.04] Python environment construction with pyenv + pipenv
Python development environment for macOS using venv 2016
[Development environment] Python with Xcode [With screen transition]
Web application created with Python + Flask (using VScode) # 1-Virtual environment construction-
Python environment construction
Django development environment construction with Docker-compose + Nginx + uWSGI + MariaDB (macOS edition)
Environment construction (python)
VScode environment construction (Windows10, Python, C ++, C, Git)
python environment construction
Python --Environment construction
Python and machine learning environment construction (macOS)
Python environment construction
python environment construction
Let's get along with Python # 0 (Environment construction)
Windows + gVim + Poetry python development environment construction
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
Get started with Python in 30 minutes! Development environment construction & learn basic grammar
Collecting information from Twitter with Python (Environment construction)
Environment construction with VSCode + Remote Container (Go / Application)
MacOS 10.11 environment construction: Powerline with Anaconda and Dein.vim
Python environment construction (Anaconda + VSCode) @ Windows10 [January 2020 version]
Build Python development environment with Visual Studio Code
[Python] Build a Django development environment with Docker
Poetry-virtualenv environment construction with python of centos-sclo-rh ~ Notes
First python ① Environment construction with pythonbrew & Hello World !!
From Python environment construction to virtual environment construction with anaconda
Get a quick Python development environment with Poetry
python windows environment construction
homebrew python environment construction
Development environment in Python
Mac environment construction Python
Virtual environment with Python 3.6
Python environment construction @ Win7
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Virtualize (isolate) IBM i python development environment with chroot
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
[Python] OpenCV environment construction with Docker (cv2.imshow () also works)
Create a python development environment with vagrant + ansible + fabric
Data analysis environment construction with Python (IPython notebook + Pandas)
Google App Engine / Python development environment construction procedure (late 2014)
Web application made with Python3.4 + Django (Part.1 Environment construction)
Python development environment with Windows + Anaconda3 + Visual Studio Code
Python development environment construction 2020 [From Python installation to poetry introduction]
Manage Python runtime packages and development environment packages with Poetry
[Python] Django environment construction (pyenv + pyenv-virtualenv + Anaconda) for macOS
Build a Python development environment using pyenv on MacOS
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Ssh to virtual environment with remote development of vscode
Set up a Python development environment with Sublime Text 2
How to set the development environment for each project with VSCode + Python extension + Miniconda
Python + Anaconda + Pycharm environment construction