配置
安装debugpy
python3 -m pip install debugpy
配置launch.json
在~/下找到.vscode文件夹,创建launch.json。在其中输入如下内容:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
}
}
]
}
使用
在终端中输入:
python3 -m debugpy --listen 5678 --wait-for-client -m xxx.py --args1 val1 --args2 val2
xxx.py是你要调试的程序,–args和val是parser要解析的参数(如使用argparse读取的参数)。运行之后,程序会进入等待状态。接下来需要你按F5(应该是在任何界面按都行)或者点击左侧debug里的绿色三角开始调试。