# How to limit a uv lockfile to supported platforms


Running `uv lock` on Linux does not limit the {{< term "lockfile" >}} to Linux. [uv](https://pydevtools.com/handbook/reference/uv.md) 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](https://pydevtools.com/handbook/how-to/how-to-use-a-uv-lockfile-for-reproducible-python-environments.md) 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 {{< term "wheel" "wheels" >}} without a [source distribution](https://pydevtools.com/handbook/reference/sdist.md). `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:

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

The {{< term "environment-marker" "environment marker" >}} 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:

```toml {filename="pyproject.toml"}
environments = ["sys_platform == 'linux'"]
```

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

Regenerate the lockfile:

```bash
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:

```toml {filename="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](https://pydevtools.com/handbook/how-to/how-to-debug-uv-dependency-resolution-failures.md).

## Check that unsupported platforms are excluded

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

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

Expect uv to reject the unsupported target:

```console
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.
