Python Fix

py Command Works but python Does Not on Windows

When py launches Python but python fails, the interpreter is usually installed correctly. The problem is how Windows resolves the python command.

Difficulty: Easy–Medium Time: 10–25 minutes Updated: July 2026 Works for: Windows 10 / Windows 11

The py and python commands are not identical on Windows. The py command uses the Python Launcher, which searches registered Python installations. The python command relies mainly on PATH and Windows aliases.

That difference explains why one command can work while the other fails. You normally do not need to reinstall every Python version. First identify which executable each command is trying to use.

Check the installed Python versions

py -0p
py --version
where py
where python

py -0p lists registered Python installations and their full paths. Keep this output because it tells you which interpreter is available and where it lives.

Fix 1 — Disable conflicting App Execution Aliases

  1. Open Settings → Apps → Advanced app settings → App execution aliases.
  2. Turn off the Store aliases for python.exe and python3.exe.
  3. Open a new terminal and test python --version.

This is especially important when where python points to the WindowsApps directory.

Fix 2 — Add the interpreter reported by the launcher to PATH

Copy the directory from py -0p, but add the folder—not the executable—to your User PATH. Add the corresponding Scripts folder as well.

C:\Users\YOUR-NAME\AppData\Local\Programs\Python\Python312\
C:\Users\YOUR-NAME\AppData\Local\Programs\Python\Python312\Scripts\

Reopen Command Prompt after saving. Existing terminals keep the old environment and will not see the new PATH immediately.

Fix 3 — Check PATH order when several versions are installed

Windows uses the first matching executable it finds. If an old Python folder appears above the active version, the command may fail or launch the wrong interpreter.

where python
python -c "import sys; print(sys.executable)"
py -c "import sys; print(sys.executable)"

Compare the two paths. If they differ, decide which version should be the default and move that version’s PATH entries above obsolete ones.

Fix 4 — Use the launcher explicitly for version-specific work

Even after fixing python, the launcher remains useful when multiple versions are installed:

py -3.12 --version
py -3.11 script.py
py -3.12 -m pip install package-name

This removes ambiguity and ensures pip installs into the intended interpreter.

Fix 5 — Repair launcher registration

If py -0p lists a path that no longer exists, remove the stale Python entry from Installed apps or rerun the installer for that version and choose Repair. Stale registrations can survive manual folder deletion.

Avoid copying or renaming python.exe manually as a workaround. It can create confusing version and package mismatches later.

Confirm Python and pip use the same installation

python -c "import sys; print(sys.executable)"
python -m pip --version

The pip output should reference the same Python directory. Prefer python -m pip over a bare pip command when several versions are present.

FAQ

Is the py command better than python?

It is better for selecting among multiple Windows Python installations. The regular command is simpler when one default version is configured correctly.

Can I keep using only py?

Yes, but some tools and tutorials expect python. Fixing PATH avoids compatibility problems.

Why does pip install into a different Python?

The bare pip command may belong to another PATH entry. Use py -3.x -m pip or python -m pip.