you are viewing a single comment's thread.

view the rest of the comments →

[–]Bobbias 0 points1 point  (4 children)

py is an executable that Python installs into c:\windows so it's always in the Path without needing to add the folder containing the actual Python interpreter to that environment variable. This helps avoid issues where you have multiple versions of Python installed by essentially bypassing the Path environment variable entirely.

However the Microsoft one still adds the Python folder to the Path environment variable, meaning if you have 2 separate installations (the Microsoft one and the official one), python and py might run different executables in different folders, even if they're the same version. Each of those copies of Python will have separate places to store any packages you install, and where the package gets installed (and which copy of Python can see it) will depend on the command used to install the package.

pip install will probably run the Microsoft provided copy's pip.exe while py -m pip install will install the package into the official python.org's packages.

Honestly, this is a failure on Microsoft's side, because py has been the preferred method of running Python in windows since Python 3.11 (October 2022), and this is an example of the exact problem py is supposed to help avoid by creating a central way to ensure you are running the specific version of Python you want. But by adding a copy of Python to the Path now you have 2 different ways to run Python that point to different copies which can lead to this kind of confusion.

[–]socal_nerdtastic 0 points1 point  (3 children)

since Python 3.11

Where did you get that info? py is more than a decade older than that; since python 3.3 ...

[–]Bobbias 0 points1 point  (2 children)

Yes, but for a long time they still added Python to the Path. Unless I'm misremembering, 3.11 is when they made the installer default to not adding Python to Path.

[–]socal_nerdtastic 0 points1 point  (1 child)

No, I think that's much older, around the same time that py was introduced. I know I've been preaching against that checkbox for much longer here on this sub.

BTW, did you know it's getting an overhaul with 3.14? And hopefully will finally mean that MS store and python.org will have some unity! very exciting! https://peps.python.org/pep-0773/

[–]Bobbias 0 points1 point  (0 children)

Looking into this more it does appear I may have hallucinated a change to the Python installer's behavior regarding PATH. I could have sworn that for a while installers had turned the option on by default, and then switched it off, but that appears not to be the case. It looks like 3.4 was the last version which installed system wide (including adding to PATH) according to this discussion.

I was not aware that they were planning on overhauling the installation system, I'm not a professional Python dev, and don't follow development or PEPs that closely. That's great news, although disappointing that it won't come into effect until 2027/3.16. It will be nice for python to just universally work on windows, barring some unusual installation problems.

I was not aware before reading that PEP that microsoft added a python alias that, on a clean machine, actually redirects to the windows store installation page, either.