diff --git a/cibuildwheel/platforms/linux.py b/cibuildwheel/platforms/linux.py index 86984a70..2ed85c02 100644 --- a/cibuildwheel/platforms/linux.py +++ b/cibuildwheel/platforms/linux.py @@ -265,7 +265,16 @@ def build_in_container( project=container_project_path, package=container_package_dir, ) - container.call(["sh", "-c", before_build_prepared], env=env) + before_build_env = env.copy() + if use_uv: + # On Linux, no virtualenv is created for the build environment + # (unlike macOS/Windows, where one is set up before before_build + # runs). uv requires either an active venv or an explicit Python + # target to install packages. Pin UV_PYTHON to the exact interpreter + # for this build so that `uv pip install` works in before_build + # without requiring users to pass --system. + before_build_env["UV_PYTHON"] = str(python_bin / "python") + container.call(["sh", "-c", before_build_prepared], env=before_build_env) log.step("Building wheel...")