VS Code Python January 2024 "Run and Debug" how to re-enable "select a debug configuration" - Stack Overflow
How to set up python debugger for VS Code? - Stack Overflow
python - Default VS Code debugger - Stack Overflow
How to debug a Python module in Visual Studio Code's launch.json - Stack Overflow
Videos
Yeah, if you're looking for these bits of the Python extension, it's moved over to the debugpy extension now. In case you missed the announcement, it's at https://code.visualstudio.com/updates/v1_86#_python-debugger-extension-installed-by-default. See also https://github.com/microsoft/vscode-python/pull/22502 and the following https://github.com/microsoft/vscode-python/pull/22738.
Make sure the ms-python.debugpy extension is installed (it should be installed automatically as part of the Python extension update), and that it's enabled. Then press F5, and when prompted to select a debugger, select "Python Debugger", and then you'll see the options you want.
I tried your suggestion but it did not work for me.
My solution (trial and error) was:
1/ uninstalling vscode via add/remove programs.
2/ using 'everything' to search for any files with 'vscode' in their name and nuking them.
3/ reinstalling vscode.
Skipping step 2 did not work-all my extensions were still there. Even with doing step 2 I must have missed some files because it still opened up in my project directory & virtual environment. However it needed python & python debugger applications reinstalling. I have no idea which bits were important and frankly I don't have the interest or means to find out.
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.
After some searching, I found that the config can be generalized for any module by the use of the Command Variable extension. Assuming that the your workspace folder is the one containing the package, the following configuration would work for any module:
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"justMyCode": true,
"module": "${command:extension.commandvariable.file.relativeFileDotsNoExtension}",
"cwd":"${workspaceFolder}"
}
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
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>
