Skip to main content

How to Change a uv Project's Python Version with uv python pin

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Sometimes a project has to move to another Python version: a library you need doesn't support the newest one yet, or your server runs an older one. In a uv project, uv python pin changes the version the project uses. This guide moves a project from Python 3.15.2 to 3.14.10 with uv 0.13.10, including the error uv gives first and the fix.

Syntax​

Syntax
uv python pin <version>
PartWhat it means
uv python pinWrites the version into the project's .python-version file
<version>The Python version to use, such as 3.14

The uv documentation explains the file it writes: "The .python-version file can be used to create a default Python version request," and "A .python-version file can be created in the current directory with the uv python pin command."

The version must also be allowed by the project's requires-python setting in pyproject.toml: uv "will respect Python requirements defined in requires-python in the pyproject.toml file during project command invocations."

The Example​

A project made on Python 3.15 moves to Python 3.14.

Prerequisites​

  • uv. This guide uses uv 0.13.10. uv downloads the Python version you pin if your computer doesn't have it.

Step 1: Create a Project and Check Its Python​

Terminal
uv init --python 3.15 pin-demo
cd pin-demo
uv run python --version
Output
Initialized project `pin-demo` at `/Users/you/source/pin-demo`
Using CPython 3.15.2 interpreter at: /Library/Frameworks/Python.framework/Versions/3.15/bin/python3.15
Creating virtual environment at: .venv
Built pin-demo @ file:///Users/you/source/pin-demo
Installed 1 package in 2ms
Python 3.15.2

The terminal after uv init --python 3.15 pin-demo and uv run python --version: uv created the project and its environment, and Python reported 3.15.2.

--python 3.15 wrote 3.15 into .python-version and >=3.15 into requires-python.

Step 2: Try to Pin Python 3.14​

Terminal
uv python pin 3.14
Output
error: The requested Python version `3.14` is incompatible with the project `requires-python` value of `>=3.15`.

The terminal after uv python pin 3.14: error: The requested Python version 3.14 is incompatible with the project requires-python value of >=3.15.

uv refused, and left .python-version as it was: requires-python = ">=3.15" says the project needs 3.15 or newer, so 3.14 isn't allowed.

Step 3: Allow Python 3.14 in pyproject.toml​

Open pyproject.toml and lower the minimum:

pyproject.toml
requires-python = ">=3.14"

The requires-python line of pyproject.toml in a macOS-style code window, set to >=3.14.

Change it only if your code really works on that version. It's a promise to everyone who installs the project.

Step 4: Pin the Version​

Terminal
uv python pin 3.14
Output
Updated `.python-version` from `3.15` -> `3.14`

The terminal after uv python pin 3.14: Updated .python-version from 3.15 -> 3.14.

Step 5: Run Python Again​

Terminal
uv run python --version
Output
Using CPython 3.14.10
Removed virtual environment at: .venv
Creating virtual environment at: .venv
Built pin-demo @ file:///Users/you/source/pin-demo
Installed 1 package in 6ms
Python 3.14.10

The terminal after uv run python --version: uv used CPython 3.14.10, removed the old .venv, created a new one, installed the project and Python reported 3.14.10.

uv saw that the environment was built for the wrong Python, so it removed .venv, made a new one with 3.14.10 and installed the project into it. Nothing else needs to be done. The commands work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Pinning a version that requires-python excludeserror: The requested Python version ... is incompatible with the project requires-python valueChange requires-python first, then pin
Editing .python-version by hand to a version requires-python excludesuv run stops: error: The Python request from `.python-version` resolved to Python 3.14.10, which is incompatible with the project's Python requirement: `>=3.15` (from `project.requires-python`)Change requires-python first, then use uv python pin, as the error suggests
Expecting the old .venv to keep workingIt's built for the old PythonLet uv run or uv sync rebuild it, as Step 5 shows

FAQ​

Where does uv get Python 3.14 if I don't have it?​

It downloads it. The documentation says: "By default, uv will automatically download Python versions if they cannot be found on the system."

Can I pin an exact patch version?​

Yes, for example uv python pin 3.14.10. A version without the last number, such as 3.14, lets uv use any 3.14 release; on this Mac it chose 3.14.10.

Conclusion​

uv python pin 3.14 refused while requires-python said >=3.15. After lowering it to >=3.14, the pin went through, and the next uv run rebuilt the environment on Python 3.14.10.

Additional Resources​