vscode python 打断点调试配置launch.json

需要直接打开项目工程文件夹,然后点击左侧的蜘蛛按钮然后点击生成launch.json

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "my-test-ddp",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true
        }
    ]
}

然后在需要执行的脚本比如main.py 按F5运行。 但是需要确认一下界面右下脚点击选择执行python的环境

其他launch.json示例

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": [
                "--img_dir",
                "/data/img",
                "--out_dir",
                "/data/save",
                "--purpose",
                "mot",
            ]
        },
        {
            "name": "dis train",
            "type": "python",
            "request": "launch",
            "program": "/usr/local/lib/python3.6/dist-packages/torch/distributed/launch.py", //可执行文件路径
            "console": "integratedTerminal",
            "justMyCode": false,
            "args": [
                "--nnodes=1",
                "--node_rank=-0",
                "--master_addr=127.0.0.1",
                "--nproc_per_node=2",
                "--master_port=29320",
                "tools/test_multi_batch.py",
                // "--config",
                // "--checkpoint",
                // "runs/s1/latest.pth",
                "--eval",
                "segm",
                "--out_dir",
                "./result/annota",
                "--eval-options",
                "classwise=True",
                "--launcher",
                "pytorch"
            ],
            "env": {
                "CUDA_VISIBLE_DEVICES": "0,1"
            },
        },
        {
            "name": "single_train",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": true,
            "args": [
                "--out_dir",
                "./result/anno_single",
            ]
        }
    ]
}

debug一闪而过或者没有任何反应

尝试着vscode的商店里面把python重新安装当前版本的以前年份,比如v2022.8.0。

有时候工作路径不是当前文件目录,需要在.vscode/launch.json添加"cwd": "${workspaceFolder}",

{
    // 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: Current File",
            "type": "python",
            "request": "launch",
            "program": "/usr/local/lib/python3.6/dist-packages/torch/distributed/launch.py",
            "console": "integratedTerminal",
            "cwd": "${workspaceFolder}",             ##################################添加这里
            "args": [
                "--nproc_per_node=1",
                 "/data/main.py", 
             ]
        }
    ]
}
posted @ 2023-02-24 15:23  无左无右  阅读(1395)  评论(0编辑  收藏  举报