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.
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.
Issues with running Python on VS Code
VS Code does not use launch.json arguments when I press Debug Python File
visual studio code - How to make VScode launch.json for a Python module - Stack Overflow
VSCode / Python / Debugging / venv?
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
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>
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?