r/learnpython • • Jun 12 '24

Python works, "py" doesn't

I'm running a windows 10 machine with Python 3.12 installed. For some reason the 'python' command works fine, but 'py' gets me "'py' is not recognized as an internal or external command, operable program or batch file."

I have python installed here: C:\Users[username]\AppData\Local\Programs\Python\Python312

And the python launcher installed here: C:\Windows\py.exe

I've added both locations to my PATH, restarted the machine, but still doesn't work.

Any help is appreciated.

0 Upvotes

35 comments sorted by

View all comments

Show parent comments

1

u/cloudiimofo Jun 12 '24

I actually got it fixed but I'm going to answer this anyway for someone else in the future.

  • Installed using the 64-bit installer for windows

  • I uninstalled, reinstalled, restarted about a million times

  • was not working from CMD, Powershell, or GitBash

Even though I ran the original installer as admin, running the 'Repair' option in the installer as admin was the only thing that fixed it.

2

u/Bobbias Jun 12 '24

Just to be clear, in case you weren't aware (and for anyone in the future who may stumble onto this):

Recent versions of python explicitly do not add the Python folder to PATH, and opt to install py.exe in C:\windows because unless you've seriously broken your PATH, C:\windows (or wherever your windows folder is) will be on there. This sidesteps needing to add it to PATH and allows you to safely install and launch multiple Python versions without causing weird conflicts by having multiple versions in PATH.

3

u/Fred776 Jun 12 '24

I got the impression OP was aware of this but that py was not working for them for some reason.

It's certainly worth telling people about it though. I find it's not as known about as maybe it should be.

1

u/Bobbias Jun 12 '24

That's precisely why I replied anyway, because they did explicitly mention adding the Python folder to PATH, which is something that recent versions are trying to avoid doing in the first place, and because many people aren't aware of these changes.

1

u/cloudiimofo Jun 12 '24

I even selected the option to add it to PATH on install but that didn't seem to actually do anything. Had to do it manually after and then use the repair utility.