查找PythonInterp

自 3.12 版本弃用: 请改用 FindPython3、FindPython2 或 FindPython。

查找 python 解释器

该模块查找是否安装了 Python 解释器并确定可执行文件的位置。此代码设置以下变量:

PYTHONINTERP_FOUND         - Was the Python executable found
PYTHON_EXECUTABLE          - path to the Python interpreter
PYTHON_VERSION_STRING      - Python version found e.g. 2.5.2
PYTHON_VERSION_MAJOR       - Python major version found e.g. 2
PYTHON_VERSION_MINOR       - Python minor version found e.g. 5
PYTHON_VERSION_PATCH       - Python patch version found e.g. 2

Python_ADDITIONAL_VERSIONS 变量可用于指定搜索 Python 时应考虑的版本号列表。您需要在调用 find_package(PythonInterp) 之前设置此变量。

如果同时调用 find_package(PythonInterp)find_package(PythonLibs),请先调用 find_package(PythonInterp) 以获取当前活动的 Python 版本,默认情况下与 PYTHON_LIBRARIES 的版本一致。

备注

为 python 版本“V”调用“find_package(PythonInterp ${V})”可能会找到一个没有版本后缀的“python”可执行文件。在这种情况下,不会尝试避免来自其他版本的 python 可执行文件。请改用 FindPython3、FindPython2 或 FindPython。