Changed in version 3.27: This module is available only if policy CMP0148 is not set to NEW.
Deprecated since version 3.12: Use FindPython3, FindPython2, or FindPython
instead.
This module finds the Python installation and determines the location of its include directories and libraries, as well as the name of the Python library to link against.
Note
When using both this and the FindPythonInterp module, call
find_package(PythonInterp) before find_package(PythonLibs). This
ensures that the detected interpreter version is used to guide the selection
of compatible libraries, resulting in a consistent PYTHON_LIBRARIES value.
This module defines the following variables:
PythonLibs_FOUNDBoolean indicating whether the (requested version of) Python libraries have
been found. For backward compatibility, the PYTHONLIBS_FOUND variable is
also set to the same value.
PYTHONLIBS_VERSION_STRINGThe version of the Python libraries found.
PYTHON_LIBRARIESLibraries needed to link against to use Python.
PYTHON_INCLUDE_DIRSInclude directories needed to use Python.
The following cache variables may also be set to specify the Python installation to use:
PYTHON_LIBRARYThe path to the Python library.
PYTHON_INCLUDE_DIRThe directory containing the Python.h header file.
This module accepts the following variables before calling
find_package(PythonLibs):
Python_ADDITIONAL_VERSIONSThis variable can be used to specify a list of version numbers that should be taken into account when searching for Python.
These variables are provided for backward compatibility:
PYTHON_DEBUG_LIBRARIESDeprecated since version 2.8.8: Use PYTHON_LIBRARIES instead.
Result variable that holds the path to the debug library.
PYTHON_INCLUDE_PATHDeprecated since version 2.8.0: Use PYTHON_INCLUDE_DIR or PYTHON_INCLUDE_DIRS instead.
Result variable that holds the path to the directory containing the
Python.h header file.
In earlier versions of CMake, Python libraries were found and used in a project like this:
find_package(PythonLibs)
target_link_libraries(app PRIVATE ${PYTHON_LIBRARIES})
target_include_directories(app PRIVATE ${PYTHON_INCLUDE_DIRS})
Starting with CMake 3.12, Python libraries can be found using the
FindPython module. The equivalent example using the modern approach
with an imported target is:
find_package(Python COMPONENTS Development)
target_link_libraries(app PRIVATE Python::Python)