I have the following minimal CMakeLists.txt:
cmake_minimum_required (VERSION 3.8)
project (myproject C CXX)
find_package (Python3 COMPONENTS Interpreter Development REQUIRED)
I use spack (https://spack.io/) to manage my dependencies, so I have a spack environment activated which contains a build of python 3.11.7, that is, this version of python is in my $PATH
, python --version
gives me “3.11.7”, $PYTHONPATH
contains the correct path for this python build, and $LD_LIBRARY_PATH
contains the path where libpython3.11.so can be found (and it does not contain “/usr/lib” or any other system path).
When I call cmake, however, I’m getting this error:
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Development
Development.Module Development.Embed) (found version "3.10.12")
Call Stack (most recent call first):
/usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.22/Modules/FindPython/Support.cmake:3180 (find_package_handle_standard_args)
/usr/share/cmake-3.22/Modules/FindPython3.cmake:490 (include)
CMakeLists.txt:3 (find_package)
The found version "3.10.12"
makes me think that cmake is finding the version of python that is in “/usr/bin”, even though “/usr/bin” comes much later in my $PATH
than the path to the python version I’m trying to use. The system-provided python doesn’t have the development libraries, which is why cmake fails, I believe.
Could you help me figure out why FindPython3.cmake finds this system-provided Python instead of the one I want to use, and how to fix this problem?