How do you find the exact Python installation path on Windows? | A1Lab@MZeeshanM to PythonEnglish • 4 days ago

How do you find the exact Python installation path on Windows?

message-square
0

Run where python in Command Prompt (where.exe python in PowerShell), execute py -0p to list every registered Python installation path on your system, or print sys.executable inside Python to see the exact python.exe path currently running.

Basic Example

:: 1. Windows Command Prompt (cmd.exe): Show all python.exe binaries on PATH in priority order
where python

:: 2. List ALL registered Python installations and their exact paths via the Windows Python Launcher
py -0p
# 3. Windows PowerShell (use where.exe because `where` is aliased to Where-Object in PowerShell)
where.exe python
(Get-Command python).Source
# 4. Inside any Python script or REPL: Print the active interpreter's exact executable path
import os
import sys

print(sys.executable)                    # e.g., C:\Users\Alice\AppData\Local\Programs\Python\Python312\python.exe
print(os.path.dirname(sys.executable))   # Installation root directory

Key Details & Edge Cases

  • Microsoft Store alias stub (WindowsApps\python.exe) trap:
    • On Windows 10/11, running where python often returns C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\python.exe first. That file is a 0-byte Windows App Execution Alias stub that opens the Microsoft Store if no real Python precedes it in PATH (or points to a sandboxed Store install).
    • Check py -0p (which queries the Windows Registry via PEP 514 and lists real installations with an * next to the default) or look past the WindowsApps entry in where python output.
  • PowerShell where alias difference:
    • In Windows PowerShell, where is a built-in alias for Where-Object, so typing where python prompts for filter parameters instead of searching PATH. Always type where.exe python or (Get-Command python).Source in PowerShell.
  • Active virtual environment vs. base system Python (sys.executable vs. sys.base_executable):
    • When a virtual environment (.venv) is active, sys.executable returns .venv\Scripts\python.exe.
    • To find the underlying base Python installation that created the virtual environment without deactivating it, inspect sys.base_executable or sys.base_prefix:
      import sys
      
      print("Active interpreter:", sys.executable)
      print("Base installation: ", sys.base_executable)
      
  • Default Windows installation directories by installer type:
    • Per-user official python.org installer: C:\Users\<User>\AppData\Local\Programs\Python\Python3XX\python.exe
    • System-wide (“Install for all users”) installer: C:\Program Files\Python3XX\python.exe
    • Miniconda / Anaconda: C:\Users\<User>\miniconda3\python.exe or C:\ProgramData\anaconda3\python.exe
    • uv-managed Python: C:\Users\<User>\AppData\Roaming\uv\python\cpython-3.XX...\python.exe

Comparison of Windows Python Path Lookup Methods

Method Environment Lists Multiple Versions? Shows Active Virtual Env? Best Used When
py -0p cmd / PowerShell Yes (all registry-registered installs) No (shows global/user installs) Discovering every Python version installed on a Windows machine and which one is default (*).
where python / where.exe python cmd / PowerShell Yes (all matches in PATH order) Yes (lists .venv\Scripts\python.exe first) Checking which python.exe runs when you type python and spotting WindowsApps stub conflicts.
sys.executable Python code / REPL No (current interpreter only) Yes Programmatically getting the exact python.exe executing your script.
sys.base_executable Python code / REPL No (base interpreter only) Resolves through venv to base Finding the parent system Python path while inside an active .venv.