Skip to content

Multiple Python versions on Windows: use py, venv and absolute paths

Verified 1 min read

Keep Python 3.11 and 3.12 side by side, create a venv per app, and pin the interpreter instead of relying on PATH or the Store alias.

Tested onStandard / Datacenter · Build 26100.33650 · x64
E1
Build
26100.33650
Edition
Standard / Datacenter
Architecture
x64
Support
Documentation (E1)
Evidence
E1Official documentation
Verified
2026-10-29
Page type
Method

Use the py launcher to select a version and a venv per app to pin dependencies:

Terminal window
py -0p
py -3.11 -m venv C:\apps\api-a\.venv
C:\apps\api-a\.venv\Scripts\python.exe -m pip install -r requirements.txt

The venv’s python.exe is the production selector. Do not rely on python from PATH, and do not install app dependencies globally.

Terminal window
py -0p
py -3.11 --version
py -3.12 --version
where.exe python

If python opens the Microsoft Store, disable the App Execution Alias or use py/absolute paths. The Store alias is a common source of “wrong Python” confusion.

Terminal window
py -3.11 -m venv C:\apps\api-a\.venv
C:\apps\api-a\.venv\Scripts\python.exe -m pip install --upgrade pip
C:\apps\api-a\.venv\Scripts\python.exe -m pip install -r C:\apps\api-a\requirements.txt

The venv records its base interpreter. Recreating it is cheaper than debugging a mixed global site-packages tree.

For a service, use the absolute venv python:

C:\apps\api-a\.venv\Scripts\python.exe -m waitress --listen=127.0.0.1:8000 app:app
Terminal window
C:\apps\api-a\.venv\Scripts\python.exe -c "import sys; print(sys.executable); print(sys.version)"
C:\apps\api-a\.venv\Scripts\python.exe -m pip list

Check sys.executable points at the app venv, not C:\Python311\python.exe.

  1. Install the new Python beside the old.
  2. Create a new venv for the app (py -3.12 -m venv .venv312).
  3. Install from the lock/requirements; run tests.
  4. Switch the service path to the new venv.
  5. Keep the old venv until rollback is no longer needed.

E1. The lab did not install multiple Python versions or run a WSGI service; the commands are the selector pattern to verify on Server 2025.

Sources