This PR resolves the issue highlighted in #31411:
Here’s another case where CMake just picks some other Python…
The fix leverages two hints for the CMake FindPython3 module:
- Python3_FIND_FRAMEWORKis set to- LAST. This ensures that Unix-style package components are preferred over frameworks on macOS. As a side effect, the- FindPython3module reports a shim or symlink (e.g., from- pyenv) rather than the underlying framework’s binary. The module’s output aligns with the result of the- whichcommand.
- Python3_FIND_UNVERSIONED_NAMESis set to- FIRST. This supports scenarios where tools like- pyenv—which use shims—have multiple Python versions installed.
Here are examples of output on my macOS 15.1.1 (Intel) with installed Homebrew’s Python 3.13.0:
- without any Python version manager:
0% which -a python3                
1/usr/local/bin/python3
2/usr/bin/python3
3% cmake -B build
4<snip>
5-- Found Python3: /usr/local/bin/python3 (found suitable version "3.13.0", minimum required is "3.10") found components: Interpreter
6<snip>
- using pyenv:
 0% pyenv versions       
 1  system
 2* 3.10.14 (set by /Users/hebasto/dev/bitcoin/.python-version)
 3  3.12.8
 4  3.13.1
 5% which -a python3
 6/Users/hebasto/.pyenv/shims/python3
 7/usr/local/bin/python3
 8/usr/bin/python3
 9% cmake -B build
10<snip>
11-- Found Python3: /Users/hebasto/.pyenv/shims/python3 (found suitable version "3.10.14", minimum required is "3.10") found components: Interpreter
12<snip>
Both variables, Python3_FIND_FRAMEWORK and Python3_FIND_UNVERSIONED_NAMES, can still be overridden by the user via the command line if needed.