'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.

Asked By: SuperAadi

||

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.

Answered By: Alexandra Dudkina
  1. Go to system properties -> Advance

  2. Click environment variables

  3. Edit the ‘PATH’ variable

  4. Add 2 new paths ‘C:Python37’ and ‘C:Python37scripts’

  5. 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
enter image description here

Press next on next window if you need nothing changed.

Then next window Select Add Python to environment variables
Continue the installation.
enter image description here

Make sure you get a new terminal to test whether it works

Answered By: Dwarkesh Kaswala

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.

Answered By: ShadowRanger
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.