Skip to content

tool.uv.environments also acts as required-environments #23271

Open

Description

@Andrej730

Question

Hi! I wanted to enforce some environments to always be satisfied for my project and initially I've added them to required-environments. A bit of a problem I've noticed that it doesn't prevent unrelated platform wheels from appearing the lockfile, so I've also added the same environments to environments. And then I've noticed that removing required-environments still keeps environments required.

Steps to reproduce:

  1. uv init .
  2. uv add --no-sync pywin32
    3, Add tool.uv below.
[tool.uv]
# Require that the package is available on the following platforms:
environments = [
    # macOS on Apple Silicon (ARM)
    "sys_platform == 'darwin' and platform_machine == 'arm64'",
    # Linux on x86_64 (Intel/AMD)
    "sys_platform == 'linux' and platform_machine == 'x86_64'",
    # Windows on x86_64 (Intel/AMD)
    "sys_platform == 'win32' and platform_machine == 'AMD64'",
]
  1. uv lock.

Results in

error: No solution found when resolving dependencies for split (markers: platform_machine == 'arm64' and sys_platform == 'darwin')
  cause: Because pywin32==312 has no `platform_machine == 'arm64' and sys_platform == 'darwin'`-compatible wheels and only pywin32<=312 is available, we can conclude that pywin32>=312 cannot be used.
         And because your project depends on pywin32>=312, we can conclude that your project's requirements are unsatisfiable.

So effectively just using environments is enough to enforce required environments. Is this expected? This does seems to contract the docs (https://docs.astral.sh/uv/reference/settings/#required-environments):

While the environments setting limits the set of environments that uv will consider when resolving dependencies, required-environments expands the set of platforms that uv must support when resolving dependencies.

For example, environments = ["sys_platform == 'darwin'"] would limit uv to solving for macOS (and ignoring Linux and Windows). On the other hand, required-environments = ["sys_platform == 'darwin'"] would require that any package without a source distribution include a wheel for macOS in order to be installable.

Which sounds like adding environments shouldn't make resolution fail.

Platform

Version

uv 0.13.8

Activity

  1. added
    question
    on Nov 17, 2026
  2. abhi478jeetur-rgb commented on Nov 17, 2026

    @abhi478jeetur-rgb

    Yes, this is expected — I reproduced your exact steps on uv 0.13.8 and got the same error, and the failure comes from the dependency being unconditional, not from environments secretly acting like required-environments.

    environments declares the platforms the project has to install on, and every dependency has to resolve in each of those forks. pywin32 ships Windows-only wheels and no sdist, so the darwin/arm64 fork has nothing it can install — that's what the error is saying. The docs line you quoted is about which platforms are considered: environments narrows that set, required-environments widens the wheel-coverage requirement. Neither one exempts a package from a platform you listed.

    One thing worth knowing: required-environments on its own doesn't get you out of this either. I tried the same three platforms under required-environments instead of environments, and it fails with the same cause (different fork label, sys_platform != 'win32'). With neither setting the lock succeeds, because then a package only needs at least one compatible wheel somewhere.

    The fix is to scope the dependency to the platform it actually supports:

    dependencies = [
        "pywin32>=312; sys_platform == 'win32'",
    ]

    With that marker, uv lock succeeds under both environments and required-environments, and the lockfile records pywin32 with the sys_platform == 'win32' marker. If your intent was "make sure these platforms are covered" rather than "support only these", required-environments plus the marker is the combination you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions