繁体   English   中英

如何使用 CMake 找到 python 解释器和库的最低版本

[英]How to find minimum versions of python interpreter and libs using CMake

我正在使用 pybind11 和 CMake 构建 C 扩展。 我曾经这样做过:

find_package(Python3 3.7 REQUIRED)
find_package(PythonLibs 3.7 REQUIRED)

没有任何问题。 现在我需要 python 3.8 并将其更改为:

find_package(PythonInterp 3.8 REQUIRED)
find_package(PythonLibs 3.8 REQUIRED)

但是,尽管 libpython3.8.so 与 libpython3.7m.so 位于同一文件夹中,但 CMake 没有找到它。 它返回:

Could NOT find PythonLibs: Found unsuitable version "3.7.5", but required
is at least "3.8" (found /usr/lib/x86_64-linux-gnu/libpython3.7m.so)

在研究这个时,我注意到 PytonInterp 和 PythonLibs 自 CMake 3.12 以来已被弃用,而 FindPython 是首选。 所以我尝试了:

find_package(Python3)

这会找到我的 python 3.8 解释器,但不是我的 python 3.8 库。 因此,我仍然不能使用 package,因为

mypy.cpython-37m-x86_64-linux-gnu.so

基于 python 3.7 库。 如何确保它也能找到我的 3.8 库? 如前所述,它们位于同一个文件夹中。

FindPython模块的文档指出:

如果未指定COMPONENTS ,则假定为Interpreter器。

所以,是的,因为您没有指定任何COMPONENTS ,所以只能找到解释器。

如果您希望 CMake 找到 Python包含目录和库,则应指定Development

find_package(Python3 COMPONENTS Interpreter Development) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM