skip to Main Content

By default the run button always runs the file you’re currently viewing, and it’s annoying because most of the time I don’t want that: I’ll be editing another file and then want to run my main.py file, so instead I have to go in the main file and then execute it. How can I change this?
I tried looking online but couldn’t find anything useful.

2

Answers


  1. Create a launch.json file in the Run and Debug panel, and then replace the configuration "program": "${file}", with "program": "./main.py",.

    enter image description here

    File structure

    pytest11
    |-.venv
    |-.vscode
    | |-launch.json
    |-demo.py
    |-main.py
    

    launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Python: Current File",
                "type": "python",
                "request": "launch",
                "program": "./main.py",
                "console": "integratedTerminal",
                "justMyCode": true
            }
        ]
    }
    

    Then select Run Without Debugging, or use the shortcut key Ctrl+F5to run the code.

    enter image description here

    Login or Signup to reply.
  2. enter image description here

    In here, may have several python terminals. Close all and compile again.

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