5

I'm trying to launch a python script on windows command prompt, but instead of it doing it, it opens the script on vscode instead. I searched the options in vscode and didn't find anything. How can I stop this behavior?

SOLVED

I simply changed the default program for .py files

3
  • What command do you use to launch it? Commented Jul 29, 2021 at 20:56
  • To solve it, set python.exe as the default app for py files, then modify PATHEXT environment variable to include .PY extension. Then you can execute python scripts directly with ./my_script.py Commented Jul 29, 2021 at 20:58
  • @abdusco I just navigated to the containing folder and typed in the file's name. also just changing the default program solved it, so thank you. Commented Jul 29, 2021 at 21:53

1 Answer 1

5

You need to change the default application for .py files to python.exe. This will instruct Windows to pass the filename of the python script you're trying to open to python.exe, which will execute it.

python my_script.py

As a bonus, if you change the PATHEXT environment variable to include .py extension. This will allow you to run a python script without prefixing it with python command when working in a shell.

./my_script.py

Python installer does this by default, but if it isn't there, you can add it.

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

Comments

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.