Debug Python With Vscode

  • python

Demo app

1
2
3
4
import sys
if __name__ == "__main__":
print(sys.version)
print(sys.argv)

Attach mode

In this mode, you can update any running para as your wish

Install debugpy

1
2
3
pip3 install debugpy
#or
pip2 install debugpy

Run your application with debugpy

1
python2 -m debugpy --listen 7777 --wait-for-client  version.py

Attach with vscode

Add lunch configure to vscode

1
2
3
4
5
6
7
8
9
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 7777
}
}

Add breakpoint and attch you program

Normal mode

Select python version

Ctrl + Shift + P -> python Select Interpreter

Launch with vscode

1
2
3
4
5
6
7
8
{
"name": "Python: launch Debug",
"type": "python",
"request": "launch",
"program": "${file}",
"console" :"integratedTerminal",
"args":["p1", "p2"]
}