Vscode - Python 调试器:无法识别的参数

Ale*_*llo 2 python visual-studio-code

我正在尝试调试一些我拥有的 Python 代码,通过在 bash 中键入以下内容,我可以毫无问题地运行这些代码:

CUDA_VISIBLE_DEVICES=0 \
python test_multi.py \
--experiment_name 128_shortcut1_inject1_none \
--test_atts Eyeglasses \
--test_ints -1.0
Run Code Online (Sandbox Code Playgroud)

我已经为 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"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

但我不断得到
test_multi.py: error: unrecognized arguments: --experiment_name 128_shortcut1_inject1_none --test_atts Eyeglasses --test_ints -1

小智 8

布雷特展示的方式不适用于我的情况。我想使用编号“1”的GPU进行调试,所以我添加 "env": {"CUDA_VISIBLE_DEVICES":"1"},launcher.json文件中。


Bre*_*non 5

您的使用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"]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)