From a76fca878dea6f18a9432ee1f0713a8634aec27b Mon Sep 17 00:00:00 2001 From: agriya khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Tue, 5 May 2026 05:39:14 +0530 Subject: [PATCH] fix: set `UV_PYTHON` for `before_build` on Linux when using `uv` (#2830) Co-authored-by: Matthieu Darbois --- cibuildwheel/platforms/linux.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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...")