Vscode - Python调试器:未识别的参数。

3

我正在尝试调试一些Python代码,通过在bash中输入以下内容即可无问题地运行:

CUDA_VISIBLE_DEVICES=0 \
python test_multi.py \
--experiment_name 128_shortcut1_inject1_none \
--test_atts Eyeglasses \
--test_ints -1.0

我已经为VScode创建了这个JSON配置文件:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "<absolute_path>/test_multi.py",
            "console": "integratedTerminal",
            "env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}],
            "args": ["--experiment_name 128_shortcut1_inject1_none", "--test_atts Eyeglasses", "--test_ints -1"]
        }
    ]
}

但我一直收到以下错误提示
test_multi.py: error: 未识别的参数: --experiment_name 128_shortcut1_inject1_none --test_atts Eyeglasses --test_ints -1

3个回答

8

对于我的情况,Brett展示的方法不适用。我想要使用编号为“1”的GPU进行调试,所以我在launcher.json文件中添加了"env": {"CUDA_VISIBLE_DEVICES":"1"}


我还添加了多个变量设置。env": {"PYTHONPATH":".", "CUDA_VISIBLE_DEVICES": "0"} - jef

7

您对args的使用存在一些问题;当它们作为单独的东西传递时,您需要将参数的每个部分视为它们自己的字符串。以下内容应该可以解决这个问题:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "<absolute_path>/test_multi.py",
            "console": "integratedTerminal",
            "env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}],
            "args": ["--experiment_name", "128_shortcut1_inject1_none", "--test_atts", "Eyeglasses", "--test_ints", "-1"]
        }
    ]
}

2

我在查看这个帖子,想了解如何在env中使用CUDA_VISIBLE_DEVICES,你的写法如下:

"env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}]

对我没有用。

我必须纠错:

"env": {"name":"CUDA_VISIBLE_DEVICES", "value":"0"}

我想方设法,只有当你有多个条目时,才需要使用[]括号?

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接