In QGIS install the plugin debugvs.
The debugvs plugin needs the python module ptvsd to function. This module is not installed by default.
In principle you just pip install ptvsd in the python interpreter used by QGIS.
I am using the QGIS OSX installer from Lutra Consulting. This installer works really great, but installing additional python modules is not very easy.
What I did was this:
- Download the
ptvsdwheel from pypi. I tried with the newest version (4.2.4), but that didnt work for me. I ended up using ptvsd-4.1.4.zip. - Unzip the wheel (if it has the extension
.whlthen rename it to.zip) - Inside the zip there are two directories. Copy the directory
ptvsdto theResources/pythonof your QGIS installation. In my case this was/Applications/QGIS3.6.app/Contents/Resources/python/.
Restart QGIS.
The default remote debugger configuration in VS Code looks like this
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},I had to change the pathMappings to get it to work:
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
]
},- In QGIS click
Plugins -> Enable Debug for Visual Studio -> Enable Debug for Visual Studio - You should now see a message in the QGIS message bar saying something like
DebugVS : Run the Debug in Visual Studio(Python:Attach) - In VS Code start debugging using the
Python: Remote Attachconfiguration defined above.
Now you should be able to set breakpoints in VS Code.

okay, here's a summary based on everyone's comments so far. (gpt-generated, but may become a part of the documentation after review)
Debugging QGIS 3.x Python Plugins on OSX using VS Code: A Comprehensive Guide
This guide is based on a gist by AsgerPetersen et al. and aims to provide a step-by-step walkthrough for debugging Python plugins in QGIS 3.x on OSX using Visual Studio Code.
Table of Contents
Installing the Plugin
debugvs.Setting Up Python Dependencies
The
debugvsplugin requires the Python moduleptvsd. Here's how to install it:ptvsdwheel from PyPI. It's recommended to use version 4.1.4..whlto.zipif needed).ptvsddirectory.Resources/pythonfolder of your QGIS installation. For example,/Applications/QGIS3.6.app/Contents/Resources/python/.Configuring VS Code
The default remote debugger configuration in VS Code needs to be modified:
launch.jsonfile.Python: Remote Attachand modify thepathMappingsas follows:{ "name": "Python: Remote Attach", "type": "python", "request": "attach", "port": 5678, "host": "localhost", "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "${workspaceFolder}" } ] }Debugging in QGIS
Plugins -> Enable Debug for Visual Studio -> Enable Debug for Visual Studio.Python: Remote Attachconfiguration.Additional Resources
Feel free to follow this guide to make your debugging process in QGIS smoother and more efficient. Happy coding!