FindPythonLibs¶
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.
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:
find_package(PythonLibs [<version>] [...])
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.
Result Variables¶
This module defines the following variables:
PythonLibs_FOUNDAdded in version 3.3.
Boolean indicating whether the (requested version of) Python libraries were found.
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.
Cache Variables¶
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.hheader file.
Hints¶
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.
Deprecated Variables¶
The following variables are provided for backward compatibility:
PYTHONLIBS_FOUNDDeprecated since version 3.12: Use
PythonLibs_FOUND, which has the same value.Boolean indicating whether the (requested version of) Python libraries were found.
PYTHON_DEBUG_LIBRARIESDeprecated since version 2.8.8: Use
PYTHON_LIBRARIESinstead.Result variable that holds the path to the debug library.
PYTHON_INCLUDE_PATHDeprecated since version 2.8.0: Use
PYTHON_INCLUDE_DIRorPYTHON_INCLUDE_DIRSinstead.Result variable that holds the path to the directory containing the
Python.hheader file.
Examples¶
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)