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 with the installer downloaded from Official Site or Homebrew Cask.
$ brew cask install qgis
I have installed the latest version (Version 3.12.3).
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.
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.
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.
OK if the message "Remote Debug for Visual Studio is running" is displayed.
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 .
Run Python: Select Interpreter from the command palette
Select "Enter interpreter path ..." and specify * / Applications / QGIS3.12.app / Contents / MacOS / bin / python3 * directly
The settings will be written to * .vscode / settings.json *.
settings.json
{
"python.pythonPath": "/Applications/QGIS3.12.app/Contents/MacOS/bin/python3"
}
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.
I have a feeling that it will be possible to develop in a familiar environment.
Recommended Posts