skip to Main Content

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?

2

Answers


  1. You have to config a launch.json file.

    • At Run & Debug (left menu) enter image description here, you can set a config file:

    enter image description here

    VS Code will try to automatically detect your debug environment, but if this fails, you will have to choose it manually:

    enter image description here

    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

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search