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

10

u/shinitakunai Jun 12 '24

I gave up on using the path python for years, not because I couldn't but because of unexpected issues like having too many libraries installed for many projects all together in dependency hell. Nowadays I just call the specific interpreter of my project venv, it is foolproof and removes all the headache. If I am lazy I just throw a .bat shortcut to the desktop and call it a day.

-3

u/iamevpo Jun 12 '24

Venv is same interpreter I think, but bifferent stack of libraries.

3

u/shinitakunai Jun 12 '24

No, when you create a venv the python.exe interpreter gets copied inside the venv folder as well, so you can just call that one

-1

u/iamevpo Jun 12 '24

It's the same. Interpreter as your base installation, right? You do not really choose a python version number with venv, I think that's not an option.

1

u/shinitakunai Jun 12 '24

What? I have many venv installed for projects, some on 3.6, some on 3.8, some on 3.11. You should give pycharm a try, it makes this extremely easy to grasp

2

u/iamevpo Jun 12 '24

venv as a tool used base interpreter version: A virtual environment is created on top of an existing Python installation, known as the virtual environment’s “base” Python. (from venv docs).

1

u/shinitakunai Jun 12 '24

Give it a try. You install python, you create a venv, you uninstall python. The venv still should work🙃

It uses the installation of python as a base to clone itself and generate that venv interpreter. But you can have many different venvs and interpreters

1

u/iamevpo Jun 12 '24

Venv would not work like rustup for making enviroments with arbitrary python versions, just that.

2

u/Bobbias Jun 12 '24

Which is not what shinitakunai said. He explained the process:

  1. Install required version of python

  2. Generate virtual environment with desired version

  3. Uninstall the version installed in step 1.

It's helpful to actually read a post before replying to it.

His post before that one, where he suggests Pycharm leaves these details out, but after your first response he clarified and explicitly outlined those steps.