How do you completely uninstall Python and remove leftover paths on Windows? | A1Lab@MZeeshanM to PythonEnglish • 3 days ago

How do you completely uninstall Python and remove leftover paths on Windows?

message-square
0

Uninstall every Python version and the Python Launcher (py.exe) through Windows Installed apps, delete leftover installation folders (%LocalAppData%\Programs\Python and C:\Python*), clear global pip caches (%LocalAppData%\pip and %AppData%\Python), and remove stale Python entries from both your User and System PATH environment variables—then open a brand-new terminal and run where python to verify that zero Python executables remain on your system.

Basic Example

# 1. Recommended: Uninstall via Windows Settings (`ms-settings:appsfeatures`),
#    OR run `winget` in PowerShell to remove all detected Python installations:
winget list --name Python
winget uninstall --id Python.Python.3.12 --silent
winget uninstall --id Python.Launcher --silent

# 2. Delete leftover Python installation directories, user site-packages, and pip caches:
Remove-Item -Recurse -Force "$env:LocalAppData\Programs\Python" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:LocalAppData\pip" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:AppData\Python" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "C:\Python*" -ErrorAction SilentlyContinue

# 3. Clean stale Python paths from the User PATH variable safely via PowerShell:
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$cleanedPath = ($userPath -split ";" | Where-Object {
    $_ -and ($_ -notmatch "\\Python\\Python\d+" -and $_ -notmatch "^C:\\Python\d+")
}) -join ";"
[Environment]::SetEnvironmentVariable("Path", $cleanedPath, "User")

Key Details & Edge Cases

  • Uninstall both Python 3.x AND Python Launcher in Windows Settings:
    • Press Win + I $\rightarrow$ Apps $\rightarrow$ Installed apps, search for Python, and uninstall every Python 3.x (64-bit) entry plus the standalone Python Launcher entry (which places py.exe inside C:\Windows\py.exe). If Python Launcher remains installed, typing py in Command Prompt or PowerShell will still resolve even after all Python interpreters are deleted.
  • Check all four common leftover directory locations on Windows:
    1. Per-user default install path: %LocalAppData%\Programs\Python (e.g., C:\Users\<user>\AppData\Local\Programs\Python\Python312\)
    2. All-users / custom root install path: C:\Program Files\Python* or C:\Python*
    3. User --user packages & scripts: %AppData%\Python (e.g., C:\Users\<user>\AppData\Roaming\Python\Python312\Scripts\)
    4. pip wheel & HTTP cache: %LocalAppData%\pip
  • Remove stale entries from both User Path and System Path (sysdm.cpl):
    • Press Win + R, type sysdm.cpl, press Enter $\rightarrow$ Advanced tab $\rightarrow$ Environment Variables….
    • Edit Path under User variables AND Path under System variables, deleting any entry ending in \Python\Python3xx\ or \Python\Python3xx\Scripts\ (or %AppData%\Python\Python3xx\Scripts).
    • Also check whether a standalone PYTHONPATH or PYTHONHOME environment variable exists in that dialog and delete it if present.
  • Disable the built-in Windows Store python.exe App Execution Alias:
    • Even after a complete uninstall, running where python on Windows 10/11 often prints C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\python.exe (a 0-byte stub that opens the Microsoft Store). Disable it via Settings $\rightarrow$ Apps $\rightarrow$ Advanced app settings $\rightarrow$ App execution aliases and toggle App Installer (python.exe and python3.exe) to Off.
  • Verify in a newly opened terminal window:
    • Existing PowerShell/CMD windows cache the old PATH in memory. Close all terminals, open a fresh PowerShell window, and verify with where.exe python and where.exe py—both should return INFO: Could not find files for the given pattern(s).

Comparison of Windows Python Cleanup Steps & Targets

Cleanup Target Exact Windows Location / Command Removed Automatically by Uninstaller? Best Used When
Core Interpreter & Stdlib Settings $\rightarrow$ Installed apps (Python 3.x & Python Launcher) Yes (leaves modified Scripts/ packages behind) First step of every Python removal on Windows.
Leftover Install & Scripts/ Folders %LocalAppData%\Programs\Python, C:\Program Files\Python*, %AppData%\Python No (directories with third-party pip packages remain) Preventing ghost pip.exe / old site-packages collisions on reinstall.
pip Download & Wheel Cache %LocalAppData%\pip No Reclaiming gigabytes of disk space or clearing corrupt cached wheels.
Stale PATH & PYTHONPATH Entries sysdm.cpl $\rightarrow$ Environment Variables (User & System Path) Partially (custom or --user Scripts paths often remain) Eliminating broken PATH lookups and ensuring a clean slate before reinstalling Python.
Windows Store Stub Aliases Settings $\rightarrow$ Apps $\rightarrow$ App execution aliases (python.exe) No (built into Windows 10/11) Stopping Windows from hijacking python commands to launch the Microsoft Store.