diff --git a/CMakeLists.txt b/CMakeLists.txt index 339ab9c6c7..02621d8336 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,19 @@ set(config_module_list) set(config_kernel_list) # Find Python +# +# Use LOCATION strategy so cmake picks the first Python3 it finds on +# PATH (matching the legacy PythonInterp behavior) instead of the newest +# system-wide version. Without this, CI runners that install PX4's +# Python deps into one interpreter (e.g. the venv on macOS, or the +# setup-python interpreter on Windows) but also have a newer system +# Python on PATH (Homebrew python@3.14, MSYS2 mingw64 python) end up +# configuring CMake with the wrong interpreter and fail at the +# kconfiglib import in cmake/kconfig.cmake. +set(Python3_FIND_STRATEGY LOCATION) +if(DEFINED ENV{VIRTUAL_ENV}) + set(Python3_FIND_VIRTUALENV FIRST) +endif() find_package(Python3 3 COMPONENTS Interpreter) # We have a custom error message to tell users how to install python3. if(NOT Python3_Interpreter_FOUND)