From 643b30c796cbdb68e5364c4e6bdd210e836bda49 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sat, 28 Mar 2026 11:28:39 -0400 Subject: [PATCH] fix: avoid PYTHON_VERSION breaking uv if set (#2795) * fix: avoid PYTHON_VERSION breaking uv if set * fix: also keep UV_PYTHON out Signed-off-by: Henry Schreiner * fix: specify the python version in the uv command more often Signed-off-by: Henry Schreiner * fix: revert env order change Signed-off-by: Henry Schreiner * Update windows.py Co-authored-by: Joe Rickerby --------- Signed-off-by: Henry Schreiner Co-authored-by: Joe Rickerby --- cibuildwheel/platforms/macos.py | 8 ++++++++ cibuildwheel/platforms/windows.py | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cibuildwheel/platforms/macos.py b/cibuildwheel/platforms/macos.py index ad084fd6..37c3d799 100644 --- a/cibuildwheel/platforms/macos.py +++ b/cibuildwheel/platforms/macos.py @@ -253,6 +253,10 @@ def setup_python( # https://github.com/pypa/virtualenv/issues/620 # Also see https://github.com/python/cpython/pull/9516 env.pop("__PYVENV_LAUNCHER__", None) + # uv uses this over the current environment's python, so remove it to avoid confusion + env.pop("PYTHON_VERSION", None) + env.pop("PYTHON_ARCH", None) + env.pop("UV_PYTHON", None) # we version pip ourselves, so we don't care about pip version checking env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" @@ -370,6 +374,8 @@ def setup_python( uv_path, "pip", "install", + "--python", + which_python, "--upgrade", "delocate", "build[virtualenv, uv]", @@ -382,6 +388,8 @@ def setup_python( uv_path, "pip", "install", + "--python", + which_python, "--upgrade", "delocate", *constraint_flags(dependency_constraint), diff --git a/cibuildwheel/platforms/windows.py b/cibuildwheel/platforms/windows.py index 18d400a9..3bb9e86f 100644 --- a/cibuildwheel/platforms/windows.py +++ b/cibuildwheel/platforms/windows.py @@ -293,7 +293,9 @@ def setup_python( # set up environment variables for run_with_env env["PYTHON_VERSION"] = python_configuration.version env["PYTHON_ARCH"] = python_configuration.arch - env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" + env.pop("UV_PYTHON", None) + if not use_uv: + env["PIP_DISABLE_PIP_VERSION_CHECK"] = "1" # update env with results from CIBW_ENVIRONMENT env = environment.as_dictionary(prev_environment=env) @@ -334,6 +336,8 @@ def setup_python( uv_path, "pip", "install", + "--python", + where_python, "--upgrade", "build[virtualenv]", *constraint_flags(dependency_constraint),