查找Python库¶
自 3.12 版本弃用: 请改用 FindPython3、FindPython2 或 FindPython。
查找 python 库
该模块查找是否安装了 Python 并确定包含文件和库的位置。它还确定库的名称是什么。此代码设置以下变量:
PYTHONLIBS_FOUND - have the Python libs been found
PYTHON_LIBRARIES - path to the python library
PYTHON_INCLUDE_PATH - path to where Python.h is found (deprecated)
PYTHON_INCLUDE_DIRS - path to where Python.h is found
PYTHON_DEBUG_LIBRARIES - path to the debug library (deprecated)
PYTHONLIBS_VERSION_STRING - version of the Python libs found (since CMake 2.8.8)
Python_ADDITIONAL_VERSIONS 变量可用于指定搜索 Python 时应考虑的版本号列表。您需要在调用 find_package(PythonLibs) 之前设置此变量。
如果你想指定使用 Python 的安装,你应该修改以下缓存变量:
PYTHON_LIBRARY - path to the python library
PYTHON_INCLUDE_DIR - path to where Python.h is found
如果同时调用 find_package(PythonInterp) 和 find_package(PythonLibs),请先调用 find_package(PythonInterp) 以获取当前活动的 Python 版本,默认情况下与 PYTHON_LIBRARIES 的版本一致。