gpt4 book ai didi

python - Cmake:找不到 Python 2.7

转载 作者:行者123 更新时间:2023-12-04 19:10:11 26 4
gpt4 key购买 nike

我有一个需要 Python 2.7 的库。因此我的 Cmake 看起来像:

set(Python_ADDITIONAL_VERSIONS 2.7)
find_package(PythonInterp 2.7 EXACT)

这失败了:
Could NOT find PythonInterp: Found unsuitable version "3.6.8", but required is exact version "2.7" (found /usr/bin/python3)

在我的系统上,我安装了几个 Python 版本(2.7、3.6 等):
$ which python 
/usr/bin/python

$ which python2
/usr/bin/python2

$ which python2.7
/usr/bin/python2.7

$ which python3
/usr/bin/python3

$ which python3.6
/usr/bin/python3.6

我在 .bashrc 设置中没有任何别名或类似的东西...如果您输入 python , python2 , 或 python2.7在命令提示符下,您将获得 python2.7口译员。

在尝试调试此问题时,我查看了 FindPythonInterp.cmake文件以查看逻辑失败的位置,似乎问题出在这一行:
find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})

具体来说,如果编辑该 cmake 文件说
find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})
message(STATUS "find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})")
message(STATUS "found ${PYTHON_EXECUTABLE}")

并重新加载我的项目,我看到了输出
-- find_program(PYTHON_EXECUTABLE NAMES python2.7;python2)
-- found /usr/bin/python3

这对我来说没有意义......似乎我要求 Cmake 找到 python2 ,但它正在返回 python3 ,即使我要求的东西完全匹配。

有人能解释一下吗...我将如何修改或替换它 find_program命令来获取正确的二进制文件?

最佳答案

哎呀。我只需要清除 Cmake 缓存。

在尝试调试一些 Python 问题时,我删除并重新安装了 python2 .当我创建构建文件夹时,python2没有安装。所以要修复,我只是删除了构建文件夹并重新创建了它。

关于python - Cmake:找不到 Python 2.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57918862/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com