VSCode python -m 调试

若运行命令为 python -m x.test --args

  1. 安装 debugpy
python3 -m pip install debugpy 
  1. 运行
python3 -m debugpy --listen 5678 --wait-for-client -m x.test --args
  1. .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
            }
        }
    ]
}
  1. 在对应代码前面打上断点
  2. 按下 Ctrl + F5F5 开始调试

参考链接

VSCode 调试在命令行输入的 Python 指令(如:带 - m 参数的 Python 指令)

你可能感兴趣的:(VSCode,Python)