Skip to content

How to limit a uv lockfile to supported platforms

Running uv lock on Linux does not limit the lockfileA file that records the exact version of every installed package, so everyone working on the project gets identical installs. to Linux. uv resolves dependencies across operating systems and CPU architectures by default. Use environments in pyproject.toml to limit that work to the platforms the project supports.

Prerequisites

Start with a uv project that has a pyproject.toml and a generated uv.lock. See How to use a uv lockfile if the project does not have one yet. Run commands from the project directory.

Choose the right setting

Goal Setting
Resolve dependencies only for supported platforms environments
Require compatible wheels for packages without a source distribution required-environments

A wheel-only package is published as prebuilt wheelsA prebuilt Python package file (.whl) that installs without compiling anything. The standard distribution format for Python packages. Learn more โ†’ without a source distribution. required-environments checks these packages; it does not prove that packages with source distributions build successfully on every target.

Limit the lockfile to Linux

For a project that supports only Linux on x86-64, add this setting under [tool.uv]. If the table already exists, add the key there instead of creating a second [tool.uv] table:

pyproject.toml
[tool.uv]
environments = [
    "sys_platform == 'linux' and platform_machine == 'x86_64'",
]

The environment markerA condition that makes a dependency apply only to matching Python versions, operating systems, implementations, or processor architectures. names the operating system and CPU architecture. For Linux on any architecture, replace the environments value with this alternative in the same [tool.uv] table:

pyproject.toml
environments = ["sys_platform == 'linux'"]

If multiple markers are listed, their platform sets must not overlap.

Regenerate the lockfile:

uv lock

A successful run prints a line beginning with Resolved and updates uv.lock for the configured platforms. Commit both pyproject.toml and uv.lock.

Require wheels for the deployment platform

For the Linux x86-64 project, add required-environments alongside environments in the existing [tool.uv] table:

pyproject.toml
required-environments = [
    "sys_platform == 'linux' and platform_machine == 'x86_64'",
]

Run uv lock again. A successful run prints Resolved; resolution fails if a selected wheel-only package lacks a compatible Linux x86-64 wheel. Commit the updated configuration and lockfile.

If locking fails with a missing-wheel error, check the platform marker in the message. Keep platforms the project must support and choose a dependency version or replacement that covers them. If the error names incompatible version ranges, follow How to debug uv dependency resolution failures.

Check that unsupported platforms are excluded

With the Linux x86-64 configuration, check a Windows target without installing packages:

uv sync --dry-run --python-platform windows

Expect uv to reject the unsupported target:

error: The current Python platform is not compatible with the lockfile's supported environments: `platform_machine == 'x86_64' and sys_platform == 'linux'`

--python-platform selects a target for this command; it does not change the lockfile’s configured platforms. A dry run does not test native builds or runtime behavior, so run CI on each supported operating system before release.

Last updated on