[CMake] FindPythonLibs fails inexplicably

Matthew LeRoy MLeRoy at minitab.com
Tue Nov 29 14:50:25 EST 2011


I'm having trouble diagnosing why a call to FIND_PACKAGE(PythonLibs) is failing.
I am running CMake 2.8.5 on Windows 7 Enterprise, 64-bit. The same CMake code
works fine on my colleagues' systems, so it's got to be something wrong on my
machine.

In my CMakeLists.txt, I've got something like this:

    ...
    find_package(PythonLibs REQUIRED)
    include_directories(${PYTHON_INCLUDE_DIRS})
    ...

When I run CMake, I get errors like this:

    PS C:\dev\build> cmake ..
    CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
      Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
    Call Stack (most recent call first):
      C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPythonLibs.cmake:108 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
      CMakeLists.txt:48 (find_package)

Curiously, if I copy the important bit out of FindPythonLibs.cmake, and stick it
in my CMakeLists.txt immediately before the call to FIND_PACKAGE, like so:

    ...
    find_library(test
        NAMES python27
        PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\Python\\PythonCore\\${_CURRENT_VERSION}\\InstallPath]/libs
        NO_SYSTEM_ENVIRONMENT_PATH)
    message("test: ${test}")
    ...

then the find_library call succeeds, but the find_package(PythonLibs REQUIRED)
still fails:

    PS C:\dev\build> cmake ..
    test: C:/Python27/libs/python27.lib  <--- SUCCESS!
    CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
      Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
    Call Stack (most recent call first):
      C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
      C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPythonLibs.cmake:108 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
      CMakeLists.txt:48 (find_package)

Interestingly, I make a call to find_package(PythonInterp REQUIRED) elsewhere
in my CMake list files, and that call succeeds with no problems. I have no idea
why CMake can find the Python interpreter successfully, but can't find the libs.

For what it's worth, I installed Python 2.7.2 using the standard x86_64 MSI
installer from python.org.

Any ideas on what could be going wrong, or how to track it down?

Many thanks!



More information about the CMake mailing list