'py' works but not 'python' in command prompt for windows 10
Question:
I installed Python on my computer.
When I type python
in the command prompt I get the following message:
'python' is not recognized as an internal or external command,
operable program or batch file.
But when I type py
it seems to be working and I get the following:
Python 3.7.0 (v3.7.0, Jun 27 2018, 04:59:51) [MSC v.1914 64
bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license"
for more information.
Why is this happening?
FYI: I checked the path variable in environmental variables and I don’t see any path to python installation.
But then how is visual code able to find the path to python.exe
and able to run python code?
I am confused.
Answers:
You could try execute in cmd:
where py
Output will be paths to the executable. E.g:
C:Usersuser>where python
C:UsersuserAnaconda3python.exe
C:UsersuserAppDataLocalMicrosoftWindowsAppspython.exe
This helps you track down, which one is executed.
-
Go to system properties -> Advance
-
Click environment variables
-
Edit the ‘PATH’ variable
-
Add 2 new paths ‘C:Python37’ and ‘C:Python37scripts’
-
Run cmd again and type python.
It should work!
Or you can use the graphical way of Python Installer.
Run the python installer and select Modify option
Press next on next window if you need nothing changed.
Then next window Select Add Python to environment variables
Continue the installation.
Make sure you get a new terminal to test whether it works
py
is itself located in C:Windows
(which is always part of the PATH
), which is why you find it. When you installed Python, you didn’t check the box to add it to your PATH
, which is why it isn’t there. In general, it’s best to use the Windows Python Launcher, py.exe
anyway, so this is no big deal. Just use py
for launching consistently, and stuff will just work. Similarly, if py.exe
was associated with the .py
extension at installation time, a standard shebang line (details in PEP linked above) will let you run the script without even typing py
.
I don’t know precisely what VSCode uses to find Python (using py.exe
directly, using a copy of Python that ships with the editor, performing registry lookup, a config file that just says where to find it, etc.), but that’s not really relevant to running your scripts yourself.
I installed Python on my computer.
When I type python
in the command prompt I get the following message:
'python' is not recognized as an internal or external command,
operable program or batch file.
But when I type py
it seems to be working and I get the following:
Python 3.7.0 (v3.7.0, Jun 27 2018, 04:59:51) [MSC v.1914 64
bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license"
for more information.
Why is this happening?
FYI: I checked the path variable in environmental variables and I don’t see any path to python installation.
But then how is visual code able to find the path to python.exe
and able to run python code?
I am confused.
You could try execute in cmd:
where py
Output will be paths to the executable. E.g:
C:Usersuser>where python
C:UsersuserAnaconda3python.exe
C:UsersuserAppDataLocalMicrosoftWindowsAppspython.exe
This helps you track down, which one is executed.
-
Go to system properties -> Advance
-
Click environment variables
-
Edit the ‘PATH’ variable
-
Add 2 new paths ‘C:Python37’ and ‘C:Python37scripts’
-
Run cmd again and type python.
It should work!
Or you can use the graphical way of Python Installer.
Run the python installer and select Modify option
Press next on next window if you need nothing changed.
Then next window Select Add Python to environment variables
Continue the installation.
Make sure you get a new terminal to test whether it works
py
is itself located in C:Windows
(which is always part of the PATH
), which is why you find it. When you installed Python, you didn’t check the box to add it to your PATH
, which is why it isn’t there. In general, it’s best to use the Windows Python Launcher, py.exe
anyway, so this is no big deal. Just use py
for launching consistently, and stuff will just work. Similarly, if py.exe
was associated with the .py
extension at installation time, a standard shebang line (details in PEP linked above) will let you run the script without even typing py
.
I don’t know precisely what VSCode uses to find Python (using py.exe
directly, using a copy of Python that ships with the editor, performing registry lookup, a config file that just says where to find it, etc.), but that’s not really relevant to running your scripts yourself.