fix(cmake): pin Python to project-local .venv on macOS (#27361)

PR #27324 swapped find_package(PythonInterp) for find_package(Python3),
whose macOS defaults (FRAMEWORK=FIRST, STRATEGY=VERSION) override
Python3_ROOT_DIR and PATH to resolve the highest-versioned framework
Python. CI then matched Homebrew's 3.14 while pip installed kconfiglib
into the actions/setup-python 3.10 venv, breaking `make px4_sitl`
configure with "No module named menuconfig".

Pin Python3_EXECUTABLE to .venv/bin/python when present (macos.sh
creates the venv but neither it nor CI exports VIRTUAL_ENV), and set
FIND_STRATEGY=LOCATION + FIND_FRAMEWORK=LAST so dev machines and Linux
containers without a venv still pick the interpreter that has the
project's pip dependencies.
This commit is contained in:
Jacob Dahl
2026-05-17 18:03:40 -04:00
committed by GitHub
parent b4b36a2748
commit 7f32786a29
+10 -3
View File
@@ -172,9 +172,16 @@ include(px4_add_module)
set(config_module_list)
set(config_kernel_list)
# Find Python. The call below sets Python3_EXECUTABLE; we then provide
# PYTHON_EXECUTABLE as a backward-compat alias for the rest of the
# codebase that still uses the legacy name.
# find_package(Python3) on macOS defaults to picking the highest-versioned
# framework Python over PATH and hints, missing the venv where pip
# installed our requirements. Pin to the project-local .venv when
# present; otherwise stop at the first location hint and keep macOS
# frameworks last. PYTHON_EXECUTABLE is bridged below for legacy callers.
if(NOT DEFINED Python3_EXECUTABLE AND EXISTS "${CMAKE_CURRENT_LIST_DIR}/.venv/bin/python")
set(Python3_EXECUTABLE "${CMAKE_CURRENT_LIST_DIR}/.venv/bin/python")
endif()
set(Python3_FIND_STRATEGY LOCATION)
set(Python3_FIND_FRAMEWORK LAST)
find_package(Python3 COMPONENTS Interpreter REQUIRED)
# Preserve PYTHON_EXECUTABLE as passed if any (e.g. via -D on command