when I open a .py file in vscode, there’s a debug button shown up at the top-right coner of the vscode window.
I have a multi-root workspace, and one launch config defined. When I start debuging/running with F5 button, the one launch config is automatically selected, and everything works fine. But if I use the debug button at the top-right coner as high-lighted, vscode complains it cannot find the modules imported in the workspace.
What debug/run environment does this button use?
2
Answers
You have to config a launch.json file.
VS Code will try to automatically detect your debug environment, but if this fails, you will have to choose it manually:
You can use IntelliSense suggestions (Ctrl+Space) to find out which attributes exist for a specific debugger. Do not assume that an attribute that is available for one debugger automatically works for other debuggers too.
I really recommend you to know more about this subject here: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
I’m pretty sure the Run Python File button invokes the same thing as the
Python: Run Python File in Terminal
command in the command palette, which- if I understand correctly- doesn’t use launch configs, and instead uses settings that start withpython.terminal.*
. The current list of those settings at the time of this writing is the following (shown with their default values):Note: docs on debugging Python can be found here: https://code.visualstudio.com/docs/python/debugging.