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
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › dev-environment › python
Python on Windows for beginners | Microsoft Learn
September 14, 2026 - Access to this page requires authorization. You can try changing directories. ... 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)
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.

Discussions

How to run a python program using windows run?
This means your windows file association has changed. You can change it back to associate py files with C:\Windows\py.exe, or you can use the command "py pingTest.py" in the run dialog, or you can make a .bat file and use that instead. https://automatetheboringstuff.com/2e/appendixb/ More on reddit.com
🌐 r/learnpython
3
1
January 7, 2021
Running a python script not in CMD
I’m going to go against the grain a little with my suggestion. Learn how to use a terminal. At some point this is going to be pretty much required. Not only that but it’s a lot easier than a GUI in most cases. More on reddit.com
🌐 r/learnpython
15
9
December 8, 2023
Python not found by command prompt
I have installed Python in Windows 11 and saved a small script called unicode.replacer.py In the command prompt, in the correct directory, when I attempt to execute: python unicode.replacer.py command prompt reports: Python was not found. Any suggestions welcome. More on discuss.python.org
🌐 discuss.python.org
19
0
February 11, 2024
Best way to use python on windows 7?

Did you install it from here?

https://www.python.org/downloads/windows/

Which version did you install? How are you trying to use Python? The way it's usually done is to open a .py file in your favourite text editor or IDE then when you want to run it, most editors/IDEs have a button or keypress you can hit to execute the current file.

More on reddit.com
🌐 r/Python
5
1
March 2, 2015
🌐
Python
docs.python.org › 3 › faq › windows.html
Python on Windows FAQ — Python 3.15.2 documentation
When you want to end your interactive Python session, call the exit() function or hold the Ctrl key down while you enter a Z, then hit the “Enter” key to get back to your Windows command prompt. You may also find that you have a Start-menu entry such as Start ‣ Programs ‣ Python 3.x ‣ Python (command line) that results in you seeing the >>> prompt in a new window. If so, the window will disappear after you call the exit() function or enter the Ctrl-Z character; Windows is running a single “python” command in the window, and closes it when you terminate the interpreter.
🌐
Humboldt State University
gsp.humboldt.edu › olm › Courses › GSP_318 › 08_3_1_RunningPythonFromTheCommandLine.html
GIS Programming With Python - Running Scripts from the Command Line
You're actually executing Python scripts one line at a time just as we do when we "single-step" in Wing. You can use this tool to practice Python commands if you wish. To exit Python, type "quit()". Leaving the command window you opened in the previous section open, open Wing and enter the following text and save it to a file. ... Once you're in the folder that contains "python.exe" it's easy to run ...
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?
🌐
Reddit
reddit.com › r/learnpython › how to run a python program using windows run?
r/learnpython on Reddit: How to run a python program using windows run?
January 7, 2021 -

I finished making a small program which opens a website and checks my ping speed for me. The problem is I don’t to open the IDE I’m using everytime I want to use the program. When I open windows run (using windows button + r) and type “pingTest.py” it opens my IDE rather than executing the script. I managed to accomplish just running the program before but I’m unable to recreate that. Let me know if I need to provide more information.

Any help would be appreciated.

🌐
GitHub
github.com › pettarin › python-on-windows
GitHub - pettarin/python-on-windows: A step-by-step guide on installing Python and using the Command Prompt for Windows · GitHub
Most Python programs are command line interface (CLI) utilities, which means that they are not operated via a graphical user interface (GUI), also known as "the program window". Instead, they must be executed in the Command Prompt of Windows, also known as "shell" or "terminal". Running a CLI program means typing a command string on the Command Prompt of Windows, following a certain syntax which depends on what the program is supposed to do.
Find elsewhere
🌐
Real Python
realpython.com › run-python-scripts
How to Run Your Python Scripts and Code – Real Python
1 week ago - You’ll start by running the program ... scripts with the python command, you need to open a command-line window and type in the word python followed by the path to your target script:...
🌐
W3Schools
w3schools.com › python › python_getstarted.asp
Python Getting Started
To test a short amount of code in python sometimes it is quickest and easiest not to write the code in a file. This is made possible because Python can be run as a command line itself. Type the following on the Windows, Mac or Linux command line:
🌐
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 - Learning how to use CMD for Python in Windows 10 is a valuable skill that allows you to run and test your Python code quickly and efficiently. By understanding how to set up and navigate the Python command line in Windows 10, you can streamline your workflow and focus more on writing code rather ...
🌐
Wikihow
wikihow.com › computers and electronics › software › programming › python › how to run a python file from the command prompt (cmd)
How to Use Windows Command Prompt to Run a Python File
October 8, 2025 - Once your computer comes back up, you will be able to run Python programs at the command prompt by typing "python <filename>". ... I want to create a shortcut that executes the utility "ptpython," running in the cmd prompt.
🌐
YouTube
youtube.com › watch
How To Run Python In Command Prompt - YouTube
#Python #ProgrammingHow to run Python in command prompt⭐Please Subscribe !⭐⭐Website: http://everythingcomputerscience.com/⭐Support the channel on Patreo...
Published: September 7, 2020
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › how-to-run-python-scripts
How to Run Python Scripts: A Step-by-Step Guide
February 6, 2024 - Executing Python scripts from the ... steps that enable users to run Python code effortlessly. ... On Windows, press Win + R, type "cmd," and press Enter....
🌐
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 - Whether you’re using Linux, Windows, or an integrated development environment like VSCode, the process is straightforward. You can run Python scripts as executables, call specific functions with command line arguments, and handle various scenarios effectively. To execute a Python script, first open a terminal, then navigate to the directory where the script is located, and finally, run the script using the ‘python’ command followed by the script’s name. On Linux, consider using python3 to ensure you’re using Python 3.
🌐
YouTube
youtube.com › watch
Python run with command prompt 👨‍💻 - YouTube
python run a .py file with cmd /terminal#python #cmd #terminal #run# *****************************# run .py file with cmd# *****************************# sav...
Published: February 1, 2021
🌐
YouTube
youtube.com › wrt tech
How To Run Python Scripts With The Command Prompt - YouTube
In this video I show you how to run python scripts with the command prompt
Published: July 19, 2020
Views: 209K
🌐
Python.org
discuss.python.org › python help
Python not found by command prompt - Python Help - Discussions on Python.org
February 11, 2024 - I have installed Python in Windows 11 and saved a small script called unicode.replacer.py In the command prompt, in the correct directory, when I attempt to execute: python unicode.replacer.py command prompt reports: Python was not found. Any suggestions welcome.
🌐
Alma Better
almabetter.com › bytes › articles › how-to-run-python-script
How to Run Python Script: A Step by Step Guide
You can pass command-line arguments to your script, making it interactive and adaptable to various scenarios. Here are some command-line options: Passing Arguments: Use python scriptname.py arg1 arg2 to pass arguments to your script. Executing Scripts in the Background: Run scripts in the ...
🌐
Ethz
iacweb.ethz.ch › staff › mathause › ip_python › intro › 05_running-python.html
Running Python — Integrated Practical: Python in Geosciences documentation
In short, it’s more “interactive” than the basic Python Shell - hence the name I(nteractive)Python. To run IPython, type the following command on your command-line terminal: