Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which launch config does the debug button at the top-right with the VS Code Python extension use?

when I open a .py file in vscode, there's a debug button shown up at the top-right coner of the vscode window.

enter image description here

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?

like image 534
H.Sheng Avatar asked Jan 23 '26 13:01

H.Sheng


2 Answers

If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.

  • https://code.visualstudio.com/docs/python/debugging#_basic-debugging

The triangle button in the upper right corner has multiple options.

enter image description here

Among them, Run Python File and Debug Python File are provided by Python extension. Run Python File executes the current script in the terminal, and Debug Python File debugs the current script.

It should be noted that Debug Python File does not use the configuration of launch.json. If you configure launch.json and want to get the effect, you should use the green triangle button to debug on the Run and Debug panel,

enter image description here

or use the Strat Debugging and Run Without Debugging under the Run menu to debugging or run script .

enter image description here

like image 72
JialeDu Avatar answered Jan 26 '26 01:01

JialeDu


If you're using the Python Debugger extension

See https://code.visualstudio.com/updates/v1_85#_github-copilot. Quoting:

The Python Debugger extension now has a configurable debug option under the Run button menu. When you select Python Debugger: Debug using launch.json and there is an existing launch.json in your workspace, it shows all the available debug configurations that you can pick to start the debugger. If there aren't any configurations, you are prompted to select a debug configuration template to use to create a launch.json file for your Python application.

If you're not using the Python Debugger extension

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 with python.terminal.*. The current list of those settings at the time of this writing is the following (shown with their default values):

// Activate Python Environment in the current Terminal on load of the Extension.
"python.terminal.activateEnvInCurrentTerminal": false,

// Activate Python Environment in all Terminals created.
"python.terminal.activateEnvironment": true,

// When executing a file in the terminal, whether to use execute in the file's directory, instead of the current open folder.
"python.terminal.executeInFileDir": false,

// When launching a python terminal, whether to focus the cursor on the terminal.
"python.terminal.focusAfterLaunch": false,

// Python launch arguments to use when executing a file in the terminal.
"python.terminal.launchArgs": [],

Note: docs on debugging Python can be found here: https://code.visualstudio.com/docs/python/debugging.

Though there is a property in python-type launch configs called "purpose", where you can put "debug-in-terminal" in the array value, which seems to make it so the launch config will apply when use the "debug in terminal" mode of the play button at the top-right of the screen.

like image 33
starball Avatar answered Jan 26 '26 01:01

starball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!