Skip to main content

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 cpython@3.10. 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.12
  • 3.12.4 - Pin to specific patch version
  • cpython@3.11 - 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
Example:
Writes /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/uv or $HOME/.config/uv
  • Windows: %APPDATA%/uv
When a local Python version pin is not found in the working directory or an ancestor directory, this version will be used instead.

Removal

--rm

Remove the Python version pin.
  • Conflicts with: request, --resolved
Example:
Deletes the .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. cpython or cp
  • <implementation>@<version> e.g. cpython@3.12
  • <implementation><version> e.g. cpython3.12 or cp312
  • <implementation><version-specifier> e.g. cpython>=3.12,<3.13
  • <implementation>-<version>-<os>-<arch>-<libc> e.g. cpython-3.12.3-macos-aarch64-none
Note: For compatibility with 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:
With --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

Creates .python-version with 3.12.

Pin to a specific patch

Creates .python-version with 3.12.4.

Pin to PyPy

Creates .python-version with pypy@3.10.

Pin with resolved path

Writes the full path to the interpreter instead of the version number.

Show current pin

Displays the contents of .python-version.

Remove pin

Deletes the .python-version file.

Set global pin

Writes to ~/.config/uv/.python-version (or equivalent on your OS).

Pin without project validation

Skips checking compatibility with pyproject.toml.

Pin for pyenv compatibility

Pin with version specifier (uv-only)

Not compatible with pyenv, but works with uv.

Use Cases

Project Python version

Team consistency

Team members running uv sync will use Python 3.12.4.

Multiple projects with different versions

uv automatically uses the correct version based on the current directory.

Migration to newer Python

Global default Python

Exact interpreter pinning (CI/CD)

Ensures the exact same Python binary is used every time.

Check and update pin

Temporary pin override

Clean slate

Compatibility Notes

pyenv Compatibility

pyenv only supports simple version numbers in .python-version:
If you need to share .python-version files with pyenv users, use only version numbers.

Version Control

Recommended: Commit .python-version to version control
Not recommended: Commit resolved paths (--resolved) Resolved paths are machine-specific and will break on other systems.

See Also