You need to add C:\Python27 to your system PATH variable, not a new variable named "python".

Find the system PATH environment variable, and append to it a ; (which is the delimiter) and the path to the directory containing python.exe (e.g. C:\Python27). See below for exact steps.

The PATH environment variable lists all the locations that Windows (and cmd.exe) will check when given the name of a command, e.g. "python" (it also uses the PATHEXT variable for a list of executable file extensions to try). The first executable file it finds on the PATH with that name is the one it starts.

Note that after changing this variable, there is no need to restart Windows, but only new instances of cmd.exe will have the updated PATH. You can type set PATH at the command prompt to see what the current value is.


Exact steps for adding Python to the path on Windows 7+:

  1. Computer -> System Properties (or Win+Break) -> Advanced System Settings
  2. Click the Environment variables... button (in the Advanced tab)
  3. Edit PATH and append ;C:\Python27 to the end (substitute your Python version)
  4. Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
Answer from Cameron on Stack Overflow
Top answer
1 of 16
234

You need to add C:\Python27 to your system PATH variable, not a new variable named "python".

Find the system PATH environment variable, and append to it a ; (which is the delimiter) and the path to the directory containing python.exe (e.g. C:\Python27). See below for exact steps.

The PATH environment variable lists all the locations that Windows (and cmd.exe) will check when given the name of a command, e.g. "python" (it also uses the PATHEXT variable for a list of executable file extensions to try). The first executable file it finds on the PATH with that name is the one it starts.

Note that after changing this variable, there is no need to restart Windows, but only new instances of cmd.exe will have the updated PATH. You can type set PATH at the command prompt to see what the current value is.


Exact steps for adding Python to the path on Windows 7+:

  1. Computer -> System Properties (or Win+Break) -> Advanced System Settings
  2. Click the Environment variables... button (in the Advanced tab)
  3. Edit PATH and append ;C:\Python27 to the end (substitute your Python version)
  4. Click OK. Note that changes to the PATH are only reflected in command prompts opened after the change took place.
2 of 16
66

Assuming you have Python2.7 installed

  1. Goto the Start Menu

  2. Right Click "Computer"

  3. Select "Properties"

  4. A dialog should pop up with a link on the left called "Advanced system settings". Click it.

  5. In the System Properties dialog, click the button called "Environment Variables".

  6. In the Environment Variables dialog look for "Path" under the System Variables window.

  7. Add ";C:\Python27" to the end of it. The semicolon is the path separator on windows.

  8. Click Ok and close the dialogs.

  9. Now open up a new command prompt and type "python"

It should work.

🌐
Python
docs.python.org › 3 › faq › windows.html
Python on Windows FAQ — Python 3.14.8 documentation
The interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your program. So, how do you arrange for the interpreter to handle your Python? First, you need to make sure that your command window recognises the word “py” as an instruction to start the interpreter.
Discussions

How to run Python Terminal
I am using Windows operating machine. In start menu I found “Python 3.12.7 (64 bit)” But when I type python-v I am not able to get the python version. I think I am missing packages maybe. Kindly have a look at the attached image and let me know how to fix the problem. More on discuss.python.org
🌐 discuss.python.org
5
0
December 17, 2024
Running Python Programs from a Terminal
Well what are you trying? What command exactly? Can you show us the complete error you are getting? Also, what OS are you using and how did you install python? More on reddit.com
🌐 r/learnpython
16
2
August 2, 2022
what is the simplest way to run a a python script?
I would be very careful before letting code, produced by Chatgpt, play with my file system. More on reddit.com
🌐 r/learnpython
22
8
February 13, 2023
Running python script works, but does not show terminal in Windows
Do you run the script by clicking on it and the something like “run in python"? Because if so, maybe try to open a cmd prompt in your folder and run it from there, python console window is also sometimes buggy on my pc as well for some reason More on reddit.com
🌐 r/learnpython
7
1
November 9, 2020
Top answer
1 of 2
1

Given that you're most familiar with Unix, I'm not sure if you are comfortable with Regedit and the Windows registry.

So let's get you a simple well-regarded tool to handle this task without asking you to manually edit the Windows registry.

First download FileTypesMan from NirSoft. It's written by Nir Sofer, who is a well-known and trusted developer. It's not open-source (unfortunately), but Nir has been publishing free tools for over 15 years with an unblemished record.

Now follow these simple steps within FileTypesMan:

  1. Find the .py file type in the top pane and click on it.
  2. In the bottom pane, find the open action (Name column) and double-click it.
  3. In the ensuing dialog box, change the command line to "C:\Windows\py.exe" "%1"
  4. In that same dialog box, ensure the Default Action checkbox is checked and the Disabled checkbox is not checked, then click OK to close the dialog box.

Voilà. You're done.

You can now close FileTypesMan.

Depending on the installed version of Windows, you may need to restart the shell. If you don't know how to do that programmatically, just log off, and log back in. Or, if you prefer, reboot.

As Gerhard mentioned in the comments, there is a significant security risk to allowing scripts to run directly like this, but you mentioned you understand the risks and the tradeoffs are worth it to you. I simply recap those comments here in this answer to help people in the future in the event that the comments get deleted.

2 of 2
1

...I want to just type "blah" to execute blah.py
- You can try:

1. Add the path to the Python.exe binary

2. Add eXtensions .py and .pyw to the PathExt variable

3. Run your files

> Your_py_Script
> Your_pyw_Script

  • How to set the Path and environment variables in Windows
  • What is the PathExt Environment Variable in Windows?
🌐
LearnPython.com
learnpython.com › blog › run-python-script-windows
How to Run a Python Script in Windows | LearnPython.com
In this article, we’ll outline how to run a Python script in Windows. In general, we recommend you work with Python 3, which is the latest version. If you need some help getting Python installed, check out our article How to Install Python on Windows. To make sure you’re up to speed with the terminology ...
🌐
Python.org
discuss.python.org › python help
How to run Python Terminal - Python Help - Discussions on Python.org
December 17, 2024 - I am using Windows operating machine. In start menu I found “Python 3.12.7 (64 bit)” But when I type python-v I am not able to get the python version. I think I am missing packages maybe. Kindly have a look at the atta…
🌐
FavTutor
favtutor.com › blogs › run-python-file-terminal
How to Run a Python File in Terminal? (Step-by-Step)
November 14, 2023 - You can run this in the terminal with the command “python gmail_script.py” and it will run the file until the terminal is closed and the system is shut down. Also, learn how to schedule scripts with a task scheduler on windows.
🌐
vteams
vteams.com › blog › how-to-run-a-python-script-in-terminal
How to Run a Python Script in Terminal Step by Step Guide
April 7, 2025 - To ace the process of how to run ... the GNOME Terminal, Konsole, and macOS’s Terminal. On Windows, you can use the Command Prompt or PowerShell....
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › running python programs from a terminal
r/learnpython on Reddit: Running Python Programs from a Terminal
August 2, 2022 -

I've new to python and trying to learn the computer language to experiment and hopefully be good enough to get a job. I bought "Python Crash Course" 2nd edition by Eric Matthes and have been researching youtube videos on the language to learn more about the program. I don't know if its just my computer or I didn't set it up right but its impossible for me to open or run a python program from my terminal. I always get hit with the "The system cannot find the path specified" whenever I try and it's becoming really frustrating. I watched a couple videos online but nothing seems to work. How do i fix this little issue?

🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › python
Python on Windows for beginners | Microsoft Learn
Get your Python environment ready on Windows in minutes — install from the command line with winget or set it up manually. You'll need the following: Python – The current stable Python runtime (3.14 or later)
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-run-a-python-script
How to Run a Python Script - GeeksforGeeks
Python Interactive Mode allows you to execute Python statements directly in the interpreter. Open Command Prompt or Terminal, type python, and press Enter. ... The print() statement is executed immediately.
Published: 3 weeks ago
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › python › how to run a python file from the command prompt (cmd)
How to Run a Python File from the Command Prompt (CMD)
October 8, 2025 - This will save your changes and ... comes back up, you will be able to run Python programs at the command prompt by typing "python <filename>"....
🌐
Real Python
realpython.com › run-python-scripts
How to Run Your Python Scripts and Code – Real Python
July 16, 2026 - How do I run a Python script from the command line?Show/Hide · To run a Python script from the command line, open a terminal or command prompt and type python followed by the path to your script file.
🌐
Digis
digiscorp.com › how-to-run-python-file-in-terminal
How to Run Python File in Terminal?
November 1, 2024 - Open Command Prompt, PowerShell, or Windows Terminal, navigate to the folder where your Python file is located, and run the file using the Python command configured on your system. In many Windows environments, this is simply python filename.py.
🌐
freeCodeCamp
freecodecamp.org › news › run-python-script-how-to-execute-python-shell-commands-in-terminal
Run Python Script – How to Execute Python Shell Commands in the Terminal
July 14, 2022 - To access the terminal on Windows, hit the Windows logo + R, type cmd, and press Enter. To access the terminal on Ubuntu, hit Ctrl + Alt + T. Python is an interpreted language.
🌐
Cambridge Core
cambridge.org › core › resources › pythonforscientists › term
Author Microsite - Using Python in a Terminal Window
Type python (in a Linux or Mac OSX terminal window) or python.exe (in a Windows command prompt window). If this works it means the computer knows where the installation of Python is located; in technical speak, it means the directory Python is located in is part of the operating system’s path.
🌐
Howchoo
howchoo.com › python › run-python-terminal
How to Run Python in Terminal
Python and associated Python scripts can be run using command-line interfaces. Windows users can use command prompt while Mac and Linux users can make use of Terminal.
🌐
Altcademy
altcademy.com › blog › how-to-run-python-in-terminal
How to run Python in terminal - Altcademy.com
September 11, 2023 - If you see a message saying that Python is not found, you'll need to install it. You can run a Python file from the Terminal by using the python command followed by the name of the file.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-cmd-for-python-in-windows-10
How to use CMD for Python in Windows 10 - GeeksforGeeks
July 15, 2025 - Now close the Environment menus by clicking ok and congratulations, we have set up the Command Prompt for Python. Now check whether it works. Open Command Prompt and type "python" and hit enter. You will see a python version and now you can ...
🌐
Altcademy
altcademy.com › blog › how-to-run-python-file-in-terminal
How to run Python file in terminal - Altcademy.com
June 13, 2023 - Windows: cd C:\Users\YourUsername\Desktop\python_projects · macOS/Linux: cd /Users/YourUsername/Desktop/python_projects · Replace YourUsername with your actual username on your computer. Now that we've navigated to the folder containing the Python file, we can run it using the python command followed by the name of the file. Type the following command in the terminal and press Enter:
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › how-to-run-python-scripts
How to Run Python Scripts: A Step-by-Step Guide
February 6, 2024 - This process consists of several steps that enable users to run Python code effortlessly. ... On Windows, press Win + R, type "cmd," and press Enter. On macOS or Linux, open the Terminal...