py.exe
is the Python Launcher for Windows and is a separate program from any given python.exe
. However, its intended purpose is to allow multiple versions of Python to be ran with minimal fuss. So, for instance, if you hypothetically needed to run Python 2.7 or Python 3.6, you could just use something like e.g. py -2.7
or py -3.6
(assuming both were versions which were installed and recognized on your system).
But for some of my programs I need to use python
in order to be able to run my code.
If you really wish to use a single version of Python from the command line, simply add the folder where your prefered python.exe
resides to your PATH/Path variable(s).
On Windows 7:
Go to Control Panel\System and Security\System
.
Click the Advanced system settings
link.
Select the Advanced
tab from the System Properties
dialog box and click the Environment Variables...
button.
Edit
your PATH (User) and/or Path (System) variables to include e.g. C:\path\to\your\preferred\python.exe
(remember to put a ;
at the end of the last listed path before putting the path to your python.exe
).
Click OK
when finished.
In Windows 10, you can:
Search for the Control Panel
from the Start Menu.
Or you can:
Search for env
from the Start Menu and click the link to edit your environment variables.
You will still need to click the Environment Variables...
button in either case under the Advanced
tab from the System Properties
dialog box.
Click Edit
and add your C:\path\to\your\preferred\python.exe
path to the appropriate PATH (User) and/or Path (System) variable list.
Click OK
when finished.
python
should now be available from the command line. If you are still having trouble running it, you may need to log out and then log back in (rebooting is typically unnecessary).
"Python" As A Batch File
While a bit of a hack, you can also "alias" py.exe
as python
with a batch file.
Create a new .txt
file and and put e.g.:
C:\path\to\your\py.exe %*
Save it and rename it to python.bat
.
Then place this batch file in your PATH\Path variable(s), as above (ex. as C:\path\to\your\python.bat
).
In this case, you're still using py.exe
in the background but using python
(a.k.a. python.bat
) to call it. The %*
notation allows any variables (e.g. script names, options, etc.) to be passed along automatically to py.exe
.
To be clear, you can simply use python
from the command line with this method. You do not need to use python.bat
.
As a final, final note, while not recommended, you could also probably simply change the name of py.exe
to python.exe
if you really wanted to.