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_FOUND
Boolean 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_STRING
The version of the Python libraries found.
PYTHON_LIBRARIES
Libraries needed to link against to use Python.
PYTHON_INCLUDE_DIRS
Include directories needed to use Python.
Cache Variables¶
The following cache variables may also be set to specify the Python installation to use:
PYTHON_LIBRARY
The path to the Python library.
PYTHON_INCLUDE_DIR
The directory containing the
Python.h
header file.
Hints¶
This module accepts the following variables before calling
find_package(PythonLibs)
:
Python_ADDITIONAL_VERSIONS
This variable can be used to specify a list of version numbers that should be taken into account when searching for Python.
Deprecated Variables¶
These variables are provided for backward compatibility:
PYTHON_DEBUG_LIBRARIES
Deprecated since version 2.8.8: Use
PYTHON_LIBRARIES
instead.Result variable that holds the path to the debug library.
PYTHON_INCLUDE_PATH
Deprecated since version 2.8.0: Use
PYTHON_INCLUDE_DIR
orPYTHON_INCLUDE_DIRS
instead.Result variable that holds the path to the directory containing the
Python.h
header 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)