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

> 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 on**

- Build: 26100.33650
- Edition: Standard / Datacenter
- Architecture: x64
- Evidence: E1
- Verified: 2026-10-29

## The short answer

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

```powershell
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.

## See what is installed

```powershell
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.

## Per-app venv

```powershell
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:

```text
C:\apps\api-a\.venv\Scripts\python.exe -m waitress --listen=127.0.0.1:8000 app:app
```

## Verify

```powershell
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`.

## Upgrade path

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.

> **Caution: Do not copy a venv between machines**
>
> A venv contains absolute paths and a base-interpreter reference. Copy `requirements.txt`/lockfile and recreate it on the target; do not zip and move `.venv`.

## Lab boundary

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

- [Python — Using Python on Windows](https://docs.python.org/3/using/windows.html)
- [Python — venv](https://docs.python.org/3/library/venv.html)
- [Python — py launcher](https://docs.python.org/3/using/windows.html#python-launcher-for-windows)

---

Source: https://windows.homes/en/server/runtimes/python-multi-version/
