Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CMake: Could not find Python3 (found version 3.9.6)

I am trying to configure CMake (v3.26.0) to find a local Anaconda installation of Python3 (on Ventura 13.3.1) I am using but I am running into an issue with CMake detecting Python. In my CMake configuration script, I have:

find_package(Python3 COMPONENTS Interpreter REQUIRED
             Python3_ROOT "${CMAKE_CURRENT_LIST_DIR}/../conda/bin")

This correctly points CMake to the location of the local Python3 interpreter. Moreover, when I run the configuration script, it appears to find Python but seems to think it hasn’t:

CMake Error at /usr/local/Cellar/cmake/3.26.0/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python3 (missing: Python3_ROOT
  /Users/xxx/xxxxx/cmake/../conda/bin) (found version "3.9.6")

I am confused; it seems to be picking up the right version of Python (i.e., I expect it to be 3.9.6) but CMake is somehow indicating that it wasn’t found. What am I doing wrong here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Taking a look at the full signature of find_package, there’s no argument Python3_ROOT. However, after REQUIRED comes [[COMPONENTS] [components...]] meaning that anything at that point will be understood as a component.

CMake’s doc puts it like this:

As a form of shorthand, if the REQUIRED option is present, the COMPONENTS keyword can be omitted and the required components can be listed directly after REQUIRED.

CMake fails to find a component of Python3 called "Python3_ROOT" and consequently reports a failure: Python3_ROOT was not found.

To give CMake paths to look for a package, use the PATHS or HINTS arguments like this:

find_package(Python3 REQUIRED COMPONENTS Interpreter
             PATHS ${CMAKE_CURRENT_LIST_DIR}/../conda/bin)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading