Specify the module you want to run with "module": "torch.distributed.launch"
You can ignore the -m flag. Put everything else under the args key.
Note: Make sure to include --nproc_per_node and the name of file (main_swav.py) in the list of arguments
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"module": "torch.distributed.launch",
"request": "launch",
"console": "integratedTerminal",
"args": [
"--nproc_per_node", "1",
"main_swav.py",
"--data_path", "/dataset/imagenet/train",
]
}
]
}
Read more here: https://code.visualstudio.com/docs/python/debugging#_module
Answer from Matt Spataro on Stack OverflowSpecify the module you want to run with "module": "torch.distributed.launch"
You can ignore the -m flag. Put everything else under the args key.
Note: Make sure to include --nproc_per_node and the name of file (main_swav.py) in the list of arguments
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "debugpy",
"module": "torch.distributed.launch",
"request": "launch",
"console": "integratedTerminal",
"args": [
"--nproc_per_node", "1",
"main_swav.py",
"--data_path", "/dataset/imagenet/train",
]
}
]
}
Read more here: https://code.visualstudio.com/docs/python/debugging#_module
This is an example of my launch.json that I use to debug Python modules.
It has an additional configuration to debug "current file" (not as module) which is useful to keep.
{
linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "path.to.module",
"args": ["run_example --arg <arg>"],
"justMyCode": true
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}
This would replicate a terminal command to run a Python module like so:
python -m path.to.module run_example --arg <arg>
Debugging an active python file that creates launch.json is debugging launch.json
Debug for reading JSON file with Python Pandas - Stack Overflow
In the debugger I often have to convert python dict to json is there a better way than evaluate expression with json.dumps()?
VS Code Debugger not working for python
Videos
As the title says I often need to convert the value of a variable in the debugger to json for other purposes. So I use the evaluate expression function and type
import json j = json.dumps(my_dict)
Then I copy the value of that "j" var to my clipboard.
I would think there should be an easier way so I don't have to repeat this over and over? I messed around int he "Customize Data View" but I couldn't get it to work the way I expected. I tried a macro but can't quite get it right. I'd like the macro to copy the name of the dict I am currently selecting dump it to json and copy the output of the dump to my clipboard.
Any info on a better way of doing this is greatly appreciated
The Python extension is broken - just seems to have updated at the same time as VS Code.
Go back to extension version v2021.12.1559732655 by clicking on the extensions control and selecting "Install another version...". Note that you will have to disable "Extensions: Auto Update", which might be a good thing. I also set "Update: Mode" to "none" for good measure.
So this bug is back with Python Extension version v2022.10.1 running on Ubuntu 18.04 with python 3.6.9.
This is a serious bug that keeps happening.
I had to roll back to extension version v2021.12.1559732655 to debug.
I'm trying to debug Python in VS Code. I click "create a launch.json file", select Python as the debugger, and then Python File.
When I click "run and debug", I get a syntax error in the monitor on the first (commented) line in the launch.json file that VS Code just created. I haven't edited the file. Why does the default file not work?
Edit: if I delete the comments, I get a different error name 'true' is not defined.
Actually, there is a very simple option to do this I found by accident while trying to edit the launch.json file.
"type": "python",
"request": "launch",
"pythonPath": "D:\\ProgramData\\Anaconda3\\envs\\simulec\\python.exe",
"module": "my_module.my_file",
Simply specify the module in the module key "module": "my_module.my_file"
The -m is not useful any more.
To add slightly to dzada's answer, which helped me a lot, a Visual Studio Code variable can be used to make this general for debugging any file that is in your module.
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "my_module.${fileBasenameNoExtension}"
}
]
}
Which is probably what you want to do.
I think the --City and Auckland are used as a single argument. Maybe try separating them like so...
Single argument
"args": ["--city","Auckland"]
Multiple arguments and multiple values
Such as:
--key1 value1 value2 --key2 value3 value4
Just put them into the args list one by one in sequence:
"args": ["--key1", "value1", "value2", "--key2", "value3", "value4"]
I also noticed that if you run the script by clicking on the debug button that looks like this
, then the arguments are not passed. However, using Run -> Start Debugging (or its shortcut F5) passed the arguments successfully.