1

Before I say anything, I want to make it clear that I am not talking about the debug menu, I am talking about this button:

When I press that run button in a different python file, in the same workspace, it'll try to run that file which I don't want. I want it to always run the main python file. (main.py for me)

I had a look at this post, but adding a launch.json to the .vscode folder didn't help.

So how do I make that Run button always execute main.py?

3
  • Did you try "Run > Run Without Debugging" section. Commented Oct 13, 2022 at 7:02
  • I have found this on Reddit. Dont know how much of a use it could be but I don't think there really is a way. Personally I prefer to run my code through CMD Pallets as it allows me to select specific files for testing and if you're writing TDD or BDD code you'll need to run the code manually anyways. Commented Oct 13, 2022 at 7:15
  • @uozcan12, yes but there is no way I'm going to get used to pressing that. Commented Oct 13, 2022 at 14:46

1 Answer 1

0

As is said in the issue you mentioned.

Add this code to your launch.json : "program": "${workspaceFolder}/main.py",

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/main.py",
            "console": "integratedTerminal"
        }
    ]
}

At the same time, you should know that launch.json is effective for debug mode, so please switch the running mode and use shortcuts F5 or Debug Python File.

Sign up to request clarification or add additional context in comments.

2 Comments

I have and, yes, I do know both these things, but I don't want to go in debug mode.
If you must use Run Python File, you can submit a request for this function to the developer in github, although they will still tell you to use the debug mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.