Skip to main content

Remote debugging of python code in Visual Studio Code



Remote debugging with python and visual studio Code


In terminal install debugpy into your environment with something like

    python -m pip install debugpy


Create a visual studio launch configuration and add following to it following (or just use vs code create configuraiton button to easily create it choose type Python and select from the list, 'Remote attach')

{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [{ "localRoot": "${workspaceFolder}", "remoteRoot": "." }]
},

Run this in the command line to start a debugging server with your script runner
python3 -m debugpy --listen 1.2.3.4:5678 --wait-for-client Yourscript.py

Now run the launch configuration from vs code to attach to this debugger

Comments