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>
Issues with running Python on VS Code
VS Code does not use launch.json arguments when I press Debug Python File
VS Code launch.json for debugging runwsgi - Development - Plone Community
Says my "Python: file" is missing from launch.json
Videos
So I have a data analysis script rn, no errors, and I ran it a month ago on the same pc with no errors and I can run it on google colab.
I had this issue on my laptop recently but I assumed it was only for my laptop. That wasn't the case. Essentially it asks nonstop, "Select a python interpreter" with 2 options that just go to the same file path, just one has a gear icon and the whole file path listed whereas the 2nd has only the end hal.f of the file path. Neither option changes anything, they both then bring up "Debug stopped, open 'launch.json' ".
After that it asks me for a directory, and it never works. I just try anyway I can to get to the Desktop (where my file is stored) and nothing pops up or even goes through.
Does anyone have a solution for this? Or any experience?
It just sucks how this happens out of the blue
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.
Hello - i would like to debug my pyhon - programs using vscode -
But how can i choose the correct venv-environment for running the program?
It seems that when i start the Debugging that it allways take the default configuration - and there are not all python-modules i need for the program - cause they are installed only in the venv.
How can i choose the venv for debugging?



