若运行命令为 python -m x.test --args
python3 -m pip install debugpy
python3 -m debugpy --listen 5678 --wait-for-client -m x.test --args
.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
}
}
]
}
Ctrl + F5
或 F5
开始调试参考链接
VSCode 调试在命令行输入的 Python 指令(如:带 - m 参数的 Python 指令)