2025-06-26

Downgrade or Upgrade Your Python Version with uv

To downgrade your project’s virtual environment e.g. from Python 3.11 to 3.10 using uv, here’s a step‑by‑step process:

1. Install the desired Python version

Run:

uv python install 3.10

This downloads and manages Python 3.10 in ~/.local/share/uv/python/... (or the equivalent on your OS) (docs.astral.sh, docs.astral.sh).

2. Pin your project to that version

Within your project directory:

uv python pin 3.10

This writes 3.10 to .python-version, ensuring that future commands use that interpreter (docs.astral.sh).

This might not work in case if your pyproject.toml file has a python requirement that prevents upgrade - edit this first, e.g. change:

requires-python = ">=3.11"

to

requires-python = ">=3.10"

You can also edit .python-version file to have it consistent with the rest of the project.

3. Recreate the virtual environment

The simplest and clean method:

rm -rf .venv
uv venv

This creates a fresh venv using Python 3.10, respecting the pin.

Alternatively, if you're managing dependencies via pyproject.toml + uv.lock:

uv sync

This will recreate the environment from locked specs using the pinned Python version (news.ycombinator.com, docs.astral.sh).

Optional: Verify interpreter version

Run:

. .venv/bin/activate
python --version  # should show Python 3.10.x