FindPythonLibs¶
在 3.27 版的變更: This module is available only if policy CMP0148 is not set to NEW.
在 3.12 版之後被棄用: 請改用 FindPython3、FindPython2 或 FindPython。
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>] [...])
備註
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.
結果變數¶
該模組定義了以下變數:
PythonLibs_FOUND在 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.
快取變數¶
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.
提示¶
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.
棄用的變數¶
The following variables are provided for backward compatibility:
PYTHONLIBS_FOUND在 3.12 版之後被棄用: Use
PythonLibs_FOUND, which has the same value.Boolean indicating whether the (requested version of) Python libraries were found.
PYTHON_DEBUG_LIBRARIES在 2.8.8 版之後被棄用: 請改用
PYTHON_LIBRARIES。Result variable that holds the path to the debug library.
PYTHON_INCLUDE_PATH在 2.8.0 版之後被棄用: 請改用
PYTHON_INCLUDE_DIR或PYTHON_INCLUDE_DIRS。Result variable that holds the path to the directory containing the
Python.hheader 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)