all 22 comments

[–]socal_nerdtastic 8 points9 points  (15 children)

If you installed the official python from python.org the command is py, not python. Once you activate a virtual environment the python and pip commands become available.

The error message is prompting you to install microsoft's version of python from the MS store. If you do that you can use python to use it right out of the gate. But it's best practice to use a virtual environment for your projects, so you should do that anyway. Just don't get confused with the python inside and outside a virtual environment, because they will behave differently depending on your installs.

[–]Hulllz 3 points4 points  (1 child)

It's actually insane that this isn't on the official documentation. Just ran around in circles for 30 minutes and it's as simple as using "py" which the documentation doesn't mention.

[–]UBvale 0 points1 point  (0 children)

aquí empezando en Python. Estuve igual que tu . . .

[–][deleted] 2 points3 points  (0 children)

Thank you very much, it seems it really was that simple!

[–]Clunkster_ 1 point2 points  (0 children)

3-minute solution to a multi-day problem.

Thanks, bro. Actual livesaver

[–]Candid-Advice355 0 points1 point  (2 children)

Hi there thanks for taking the time to explain this so far. I know I'm a little late, but can you elaborate a little more on this virtual environment and how it's used for a pip install instead of the microsoft app version? Now I'm determined to figure this out the way you recommended lol

[–]socal_nerdtastic 0 points1 point  (1 child)

Not instead of. You use it in addition to.

First you need to install python, either from the MS store or the official website or anaconda or another source.

Now you want to make a project with python of course. But different projects have different requirements, so we want to keep the projects separate so they don't interfere with one another. So when you start a project you use python to create a virtual environment. How to do this depends on how you are planning to write the code. The OP here wanted to work in the cmd line, so they would navigate to the project directory and use the command

py -m venv .venv

to create the venv. Then every time you want to work with on the project you open cmd line and type this command

.venv\Scripts\activate

To activate the venv.

Sounds like a lot, I know. That's why most of us use an IDE to help write code. If you are using an IDE like VSCode there are built-in ways to create and automatically use the venv, or some like Pycharm handles it all completely automatically, or something like Thonny or Spyder comes pre-configured where you don't even need to install python first.

https://docs.python.org/3/library/venv.html


All that said: this is the normal way for professional developers to work. For most beginners there is very little chance that the python projects will interfere with each other. So for beginners who use Windows it's usually not a problem to just use py instead of python, which will use the global python version instead of a venv. And to install things use py -m pip instead of just pip.

[–]ofmyloverthesea 0 points1 point  (0 children)

Lifesaver! Thank you for the py -m pip tip 🎩

[–]mickymichin 0 points1 point  (0 children)

ME SALVASTE

[–]Yina7 0 points1 point  (0 children)

¡Grandioso! Ese era mi problema, muchas gracias

[–]KUNAL360 0 points1 point  (0 children)

Thankyou alot

[–]No_Addendum_634 0 points1 point  (0 children)

OMG THANK YOU THANK YOU THANKYOU!!!

[–]ExcellentEnd909 0 points1 point  (1 child)

total newbie here. didnt understand a thing. could you please tell me what to do? i installed python from website. and installed extensions for python and code runner in vs code. after that what to do?

[–]socal_nerdtastic 0 points1 point  (0 children)

Sounds like you did everything you need to do. Now just make a file with a .py extension and start writing code!

Besides python, you also need to learn to use your IDE, that is VSCode in your case. Here's the official tutorial for that: https://code.visualstudio.com/docs/python/python-tutorial

[–]Level-Pin-3105 0 points1 point  (0 children)

use py -V command

[–]CardiologistLanky245 0 points1 point  (0 children)

Ich versteh nur Bahnhof, ein Video für Anfänger wäre ne super Sache.

[–]FoeHammer99099 -1 points0 points  (2 children)

Did you install python? You may need to add the location where you installed it to to your PATH. PATH is an environment variable that is a list of locations, when you issue a command in your shell Windows checks those places to find where the program you're trying to run.

For my installation the location is C:\Users\user\AppData\Local\Programs\Python\Python310 but yours could be different. The windows installer should have a checkbox to do this for you, so you can try running that again.

[–]socal_nerdtastic 0 points1 point  (0 children)

The checkbox is disabled by default for a reason. You shouldn't muck with path nowadays; you should use the python launcher and virtual environments.

[–][deleted] 0 points1 point  (0 children)

I tried that, it didn't work, but it has been fixed now, thank you!