troubles with find_package and CMAKE_PREFIX_PATH

Hello,

i have the problem that i’ve build cpython on my own in /home/stuv/build/cpython and i set CMAKE_PREFIX_PATH to this path but when i try

find_package(
Python3
REQUIRED VERSION 3.13
COMPONENTS Development
)

he tells me he can only find the version 3.11 which is the system installed one. is there a way i can tell cmake which version i wold prefer or why he doesn’t he find my version from the build dir ?

Maybe you have to install your build (make install) to have a correct layout to be searchable…

i’ve done so now with --prefix and put the builded version into /home/user/build/python3.13 and my code looks like:
cmake_minimum_required(VERSION 3.5)
project(TestPython)

set(EXTERNAL_BUILD_PATH /home/user/build/python3.13)
list(APPEND CMAKE_PREFIX_PATH ${EXTERNAL_BUILD_PATH})
find_package(
Python
version 3.13
REQUIRED
PATHS ${EXTERNAL_BUILD_PATH}
)

if(Python_FOUND)
message(“python was found”)
elseif()
message(“python was not found”)
endif()

and it gives me the error message find_package called with invalid argument “version” …

As the error message said, version is not a valid argument to find_package() command. The version can be specified but without keyword:

find_package(Python 
3.13
REQUIRED
PATHS ${EXTERNAL_BUILD_PATH}
)

i now get the output:
CMake Error at /usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python3 (missing: PATH /home/stuv/build/python3.13) (found
suitable version “3.13.0”, minimum required is “3.13.0”)
Call Stack (most recent call first):
/usr/local/share/cmake-3.28/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.28/Modules/FindPython/Support.cmake:3867 (find_package_handle_standard_args)
/usr/local/share/cmake-3.28/Modules/FindPython3.cmake:545 (include)
CMakeLists.txt:56 (find_package)

so it looks like he can find the version but has some othe trouble, i set Python_DIR to /home/user/build/python3.13

Configuring with the --debug-find may help figure out why that PATH bit is considered missing.