Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

60%
+1 −0
Q&A Why can't I run freshly-installed Python from the command line on Windows?

Why the installed Python isn't found By default, Windows installers for Python install Python in a folder that is not listed in the PATH environment variable. This means that executables in that f...

posted 14d ago by Karl Knechtel‭

Answer
#1: Initial revision by user avatar Karl Knechtel‭ · 2024-06-18T14:16:32Z (14 days ago)
## Why the installed Python isn't found

By default, Windows installers for Python install Python in a folder that is **not listed in the `PATH` environment variable**. This means that executables in that folder won't be found by name; the command line needs an explicit path to them.

<details><summary>Rationale</summary>

Generally, programs installed "for all users" on Windows go into separate folders, side by side, within `C:\Program Files` (or a similarly named directory). Each program is bundled together with its associated libraries, documentation etc. in its own folder. This is different from the default Linux organization, where the main programs go *directly* side-by-side in `/usr/bin` (or similar) and the supporting files might go into `/usr/lib`, `/usr/share` (for documentation), etc. Because of this, installers for Windows programs need to add that sub-folder to `PATH` to make the program discoverable - entries on `PATH` are **only checked directly, not searched**.

Since the introduction of the [Python Launcher for Windows](https://docs.python.org/3/using/windows.html#python-launcher-for-windows) in 2011, the default choice in the Windows installer is **not** to add the new Python to `PATH`. This is partly to avoid polluting the `PATH` (or even corrupting it: [there's a length limit](https://devblogs.microsoft.com/oldnewthing/20100203-00/?p=15083), and [lots of other programs want to add themselves too](https://stackoverflow.com/questions/4405091)), and partly to avoid confusion [when multiple versions are installed](https://software.codidact.com/posts/291616).

After all, the entire point of the launcher is that it uses its own logic to find a Python installation (and it can even emulate how Linux treats shebang lines). So, since every installer ensures that the launcher is available, there's no *need* to add to `PATH` - unless you want `python` to work as a command instead of `py`.
</details>

## Fixing the problem

It's recommended to use the Python Launcher for Windows, even with a single installation, for consistent results.

It's also possible to "repair" the installation and choose to add Python to the `PATH` by checking that box in the installer interface. **Please carefully read every option in every installer you're given**, as a general good habit; they aren't just there to annoy you.

You can also add the appropriate path to `PATH` explicitly from the command line or from the Windows GUI. Make sure you understand [how to make these changes permanent](https://superuser.com/questions/1336841).

<section class="notice is-success">

Finally, you can always [just use a virtual environment. They fix everything, really.](https://software.codidact.com/posts/291740)
</section>

## About the Microsoft Store[^1]

<details><summary>The fact that you may get an offer to install Python when you already have it, results from an amusing combination of events.</summary>

[In May 2019](https://devblogs.microsoft.com/python/python-in-the-windows-10-may-2019-update/), a Windows 10 update added some Microsoft Store "helpers" for Python. The idea was to make it easier for Windows users who wanted to learn Python, to obtain it and start using it right away - without having to do research to find the Python web site, for example. So if a new student tried to run `python`, Windows would provide a helpful message and a direct way to install Python - without needing to pre-install it as part of Windows.

[Unfortunately,](https://dev.to/naruaika/why-i-didn-t-install-python-from-the-microsoft-store-5cbd) there are some serious drawbacks to installing Python this way. It bypasses the "lengthy" setup wizard... which contains some options that some users find very useful. The update apparently also caused other issues for some users who already had Python installed when the update was released. Finally, this distribution of Python is a bit non-standard - in particular, because it's a Store app, it [has limitations](https://docs.python.org/3.11/using/windows.html#known-issues) on file system access. Hilariously, at first, [`py` didn't know how to launch the Store version of Python](https://docs.python.org/3.7/using/windows.html#known-issues), either.

In order to make sure that these helpers are found, Windows puts their containing folder on the `PATH`. To *try to* make sure that the helpers are *only* found when Python is *not* installed, Windows puts said folder at the *end* of the `PATH`.

Which would work brilliantly, if it weren't for the fact that official Python installers had, for the last 8 years or so, been defaulting to *not* adding the newly installed Python to the `PATH`.

Oops.

(You'd think someone at Microsoft would have been aware of the potential issue. Maybe instead of a special shortcut link, they could have made an actual script that checks whether the launcher is installed. Considering that it would always be named `%WINDOWS%\py.exe`, that ought to be pretty easy. I'm rather disappointed at the failure to coordinate, honestly.)
</details>

Anyway, you can disable the Microsoft Store shortcuts [by disabling the corresponding "App Execution Aliases"](https://stackoverflow.com/questions/58754860) from the Windows GUI. It's a good idea to do this even if you already have `python` working at the command line, just to reduce the risk of future annoyance.

[^1]: This section is adapted [from my original Stack Overflow answer](https://stackoverflow.com/a/70830617/523612).