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

时间:2019-06-25 15:30:22

标签: 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

我已经为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: unrecognized arguments: --experiment_name 128_shortcut1_inject1_none --test_atts Eyeglasses --test_ints -1

1 个答案:

答案 0 :(得分:1)

您对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"]
        }
    ]
}