Skip to content

Instantly share code, notes, and snippets.

@AsgerPetersen
Last active January 5, 2026 09:27
Show Gist options
  • Select an option

  • Save AsgerPetersen/9ea79ae4139f4977c31dd6ede2297f90 to your computer and use it in GitHub Desktop.

Select an option

Save AsgerPetersen/9ea79ae4139f4977c31dd6ede2297f90 to your computer and use it in GitHub Desktop.
Debugging QGIS 3.x python plugins on OSX using VS Code

Debugging QGIS 3.x python plugins on OSX using VS Code

Plugin

In QGIS install the plugin debugvs.

Python dependencies

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:

  1. Download the ptvsd wheel 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.
  2. Unzip the wheel (if it has the extension .whl then rename it to .zip)
  3. Inside the zip there are two directories. Copy the directory ptvsd to the Resources/python of your QGIS installation. In my case this was /Applications/QGIS3.6.app/Contents/Resources/python/.

Restart QGIS.

Setting up VSCode

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}"
        }
    ]
},

Debugging

  • 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 Attach configuration defined above.

Now you should be able to set breakpoints in VS Code.

@dubiduba
Copy link

dubiduba commented Dec 23, 2025

Hello, I managed to connect just by setting debugpy.configure( # path to interpreter). However, it would run just once. Then GPT proposed the following, which worked for me:

import sys

if not getattr(sys, "_qgis_debugpy_started", False):
import debugpy
debugpy.configure(python=r"/Applications/QGIS-LTR.app/Contents/MacOS/bin/python3")
debugpy.listen(5678)
sys._qgis_debugpy_started = True
print("Waiting for debugger...")
debugpy.wait_for_client()

from qgis.core import QgsProject
print(QgsProject.instance())

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