How to Run a Python Script in Windows

You can run a Python script on Windows from Terminal, by double-clicking it, or from an editor. First install Python from python.org or the Microsoft Store. Python now recommends the Python install manager for Windows; the traditional full installer is being phased out from Python 3.14.

Quick Answer

Open Terminal in the folder that holds your script and type py script.py (or python script.py), then press Enter.

How to Run a Python Script in Windows

  1. Install Python if you have not. Type py –version in Terminal to check.
  2. Save your code as a file ending in .py, for example hello.py.
  3. Open File Explorer, go to the folder, right-click an empty area and choose Open in Terminal.
  4. Type py hello.py and press Enter.
  5. If py is not found, try python hello.py.
  6. To pass arguments, add them after the file name, for example py hello.py input.txt.
Terminal window running a Python script with the py command
Type py and the file name to run a script.

Ways to Run a Script

Method Notes
py script.py in Terminal Uses the Python launcher; picks the right version
python script.py Works when Python is on PATH
Double-click the .py file Window closes when the script ends
IDLE, Run, Run Module (F5) Comes with Python
Code editor Run button Needs the Python extension

Related: how to install pygame.

See also running .sh scripts on Windows.

Troubleshooting

  • Python opens the Microsoft Store instead: turn off the python.exe app execution alias in Settings, Apps, Advanced app settings.
  • Not recognized as a command: add Python to PATH or use py.
  • Window closes too fast: run from Terminal instead of double-clicking.
  • Related: adding Python to PATH and checking if Python is installed.

Related: Split a word or string in Python.

Related: Fix the list assignment index out of range error in Python.

Related: Avoid TypeError when formatting strings in Python.

Related: Find your Python path in Windows.

Frequently Asked Questions

What is the difference between py and python?

py is the Windows launcher that finds installed versions. python runs whichever version is first on PATH.

How do I run a specific version?

Use py -3.13 script.py, for example.

Can I schedule a script?

Yes, with Task Scheduler.

Do I need admin rights?

No, not for running scripts.

Summary

  1. Install Python.
  2. Save the script.
  3. Open Terminal in its folder.
  4. Type py script.py.
  5. Press Enter.