Vscode - Python Debugger: unrecognized arguments

Viewed 2275

I'm trying to debug some Python code I have which I can run with no problem by typing the following in bash:

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

I've created this json config file for VScode:

{
    "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"]
        }
    ]
}

but I keep getting
test_multi.py: error: unrecognized arguments: --experiment_name 128_shortcut1_inject1_none --test_atts Eyeglasses --test_ints -1

3 Answers

Your use of args is slightly off; you need to treat each part of your arguments as their own string when they are to be passed in as individual things. The following should fix it:

{
    "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"]
        }
    ]
}

I was looking at this thread to see how I could use CUDA_VISIBLE_DEVICES in env and the way you wrote it down, here:

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

, didn't work for me. I had to correct it to:

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

I imagine the []- brackets are only expected when you have more then one entry?

The way Brett shows didn't work with my case. I want to use the Number "1" GPU for debugging, so I added "env": {"CUDA_VISIBLE_DEVICES":"1"}, to the launcher.json file.

Related