Synopsis
Description
Pin to a specific Python version. Writes the pinned Python version to a.python-version file, which is used by other uv commands to determine the required Python version.
If no version is provided, uv will look for an existing .python-version file and display the currently pinned version. If no .python-version file is found, uv will exit with an error.
See uv help python to view supported request formats.
Arguments
[REQUEST]
The Python version request.
uv supports more formats than other tools that read .python-version files, i.e., pyenv. If compatibility with those tools is needed, only use version numbers instead of complex requests such as [email protected].
If no request is provided, the currently pinned version will be shown.
See uv help python to view supported request formats.
Examples:
3.12- Pin to Python 3.123.12.4- Pin to specific patch version[email protected]- Pin to CPython 3.11>=3.10- Pin with version specifier (not compatible with pyenv)
Options
Pin Behavior
--resolved
Write the resolved Python interpreter path instead of the request.
Ensures that the exact same interpreter is used.
This option is usually not safe to use when committing the .python-version file to version control.
- Conflicts with:
--no-resolved
/Users/user/.local/share/uv/python/cpython-3.12.8-macos-aarch64-none/bin/python3.12 instead of 3.12.
--no-resolved
Write the request instead of the resolved path.
This is the default behavior.
- Conflicts with:
--resolved
Validation
--no-project
Avoid validating the Python pin is compatible with the project or workspace.
By default, a project or workspace is discovered in the current directory or any parent directory. If a workspace is found, the Python pin is validated against the workspace’s requires-python constraint.
Aliases: --no-workspace
Scope
--global
Update the global Python version pin.
Writes the pinned Python version to a .python-version file in the uv user configuration directory:
- Linux/macOS:
$XDG_CONFIG_HOME/uvor$HOME/.config/uv - Windows:
%APPDATA%/uv
Removal
--rm
Remove the Python version pin.
- Conflicts with:
request,--resolved
.python-version file.
Version Request Formats
The following Python version request formats are supported:<version>e.g.3,3.12,3.12.3<version-specifier>e.g.>=3.12,<3.13<version><short-variant>e.g.,3.13t,3.12.0d<version>+<variant>e.g.,3.13+freethreaded,3.12.0+debug<implementation>e.g.cpythonorcp<implementation>@<version>e.g.[email protected]<implementation><version>e.g.cpython3.12orcp312<implementation><version-specifier>e.g.cpython>=3.12,<3.13<implementation>-<version>-<os>-<arch>-<libc>e.g.cpython-3.12.3-macos-aarch64-none
pyenv, use only simple version numbers like 3.12 or 3.12.4.
File Format
The.python-version file contains a single line with the Python version:
--resolved, it contains the full path:
Output Format
Pinning a Version
Showing Current Pin
No Pin Found
Removing Pin
Validation Error
Examples
Pin to a minor version
.python-version with 3.12.
Pin to a specific patch
.python-version with 3.12.4.
Pin to PyPy
.python-version with [email protected].
Pin with resolved path
Show current pin
.python-version.
Remove pin
.python-version file.
Set global pin
~/.config/uv/.python-version (or equivalent on your OS).
Pin without project validation
pyproject.toml.
Pin for pyenv compatibility
Pin with version specifier (uv-only)
pyenv, but works with uv.
Use Cases
Project Python version
Team consistency
uv sync will use Python 3.12.4.
Multiple projects with different versions
Migration to newer Python
Global default Python
Exact interpreter pinning (CI/CD)
Check and update pin
Temporary pin override
Clean slate
Compatibility Notes
pyenv Compatibility
pyenv only supports simple version numbers in .python-version:
.python-version files with pyenv users, use only version numbers.
Version Control
Recommended: Commit.python-version to version control
--resolved)
Resolved paths are machine-specific and will break on other systems.
See Also
uv python install- Download and install Python versionsuv python find- Find a Python installationuv python list- List available Python installationsuv python uninstall- Uninstall Python versions