How do you safely upgrade Python to a newer version on Windows 10? | A1Lab@MZeeshanM to PythonEnglish • 3 days ago

How do you safely upgrade Python to a newer version on Windows 10?

message-square
0

Install the new Python 3.x release side-by-side (using the official Windows installer from python.org or winget install Python.Python.3.x), switch versions cleanly via the Windows Python Launcher (py -3.x), and recreate your project virtual environments from requirements.txt rather than overwriting or deleting your existing Python installation first.

Basic Example

# 1. Export current global packages (if any) before upgrading
python -m pip freeze > backup_requirements.txt

# 2. Install the new Python minor version side-by-side via Windows Package Manager (winget)
#    (Or download the 64-bit Windows installer from [https://www.python.org/downloads/windows/](https://www.python.org/downloads/windows/))
winget install --id Python.Python.3.13 -e --source winget

# 3. Verify both old and new versions coexist cleanly via the Windows Python Launcher (`py`)
py --list
# Output:
#  -V:3.13 *        Python 3.13 (64-bit)
#  -V:3.11          Python 3.11 (64-bit)

# 4. Recreate your project's virtual environment using the new interpreter
py -3.13 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt

Key Details & Edge Cases

  • Minor version upgrades (3.11 $\rightarrow$ 3.13) NEVER auto-upgrade in place on Windows:
    • Windows treats each major.minor release (Python 3.11, Python 3.12, Python 3.13) as a completely separate installation directory (%LocalAppData%\Programs\Python\Python313\). Patch releases (3.13.0 $\rightarrow$ 3.13.2) update in place when you run the matching 3.13.x installer, whereas new minor releases install alongside older ones.
  • Existing virtual environments (.venv) break if you uninstall the old Python version:
    • A Windows .venv contains hard links/symlinks and pyvenv.cfg pointers tied directly to the exact python.exe path it was created with. Always recreate virtual environments (rmdir /s /q .venv then py -3.13 -m venv .venv) before uninstalling the old Python version from Settings $\rightarrow$ Apps $\rightarrow$ Installed apps.
  • Check "Add python.exe to PATH" and "Install py launcher" in the python.org installer:
    • If you use the GUI installer from python.org, select “Add python.exe to PATH” on the first screen (or click Customize installation $\rightarrow$ check py launcher and Disable path length limit at the end to prevent MAX_PATH 260-character errors during pip install).
  • Avoid the Microsoft Store Python alias trap (App execution aliases):
    • Windows 10 ships with stub python.exe / python3.exe shims in %LocalAppData%\Microsoft\WindowsApps that open the Microsoft Store or shadow your new python.org installation if placed higher in PATH. If python --version still reports an older version after installing, verify your PATH order with where python in Command Prompt / PowerShell or disable the stub aliases under Settings $\rightarrow$ Apps $\rightarrow$ App execution aliases.
  • Verify third-party C-extension wheel compatibility before deleting your old Python:
    • Brand-new Python releases (e.g., within weeks of a 3.x.0 launch) may temporarily lack prebuilt binary wheels for heavy packages like torch, scipy, or numpy, forcing slow source compilations. Keeping your previous Python installed side-by-side lets you run py -3.11 immediately if a dependency isn’t ready yet.

Comparison of Windows 10 Python Upgrade Methods

Upgrade Method Side-by-Side Coexistence? Updates PATH & py Launcher? Keeps Existing .venvs Working? Best Used When
python.org Official Installer (Recommended) Yes (separate Python3X folder) Yes (check "Add python.exe to PATH") No (recreate .venvs with py -3.X -m venv .venv) Full control over custom install path, py launcher, and MAX_PATH disable toggle.
winget install Python.Python.3.X Yes Yes No (recreate .venvs) Fast, scriptable command-line installation on Windows 10 (1809+) without browser downloads.
uv python install 3.13 Yes (managed independently by uv) Manages per-project .venvs automatically No (recreate .venv via uv venv -p 3.13) Developers managing multiple Python versions per project without touching system PATH.
Microsoft Store Python Yes (sandboxed app container) Uses WindowsApps execution aliases No Avoid for serious development—sandboxed filesystem paths frequently break pip, venv, and IDEs.