【发布时间】:2019-03-06 11:27:03
【问题描述】:
这是我正在使用的 CMakeLists.txt 文件的开头:
cmake_minimum_required(VERSION 3.12)
project(hello-pyext)
find_package(Python3 COMPONENTS Interpreter Development)
message(STATUS
"Python: version=${Python3_VERSION} interpreter=${Python3_EXECUTABLE}")
if(NOT Python3_FOUND AND Python3_Development_FOUND)
# find_package() will not abort the build if anything's missing.
string(JOIN "\n" errmsg
" Python3 and/or development libs not found."
" - Python3_FOUND=${Python3_FOUND}"
" - Python3_Development_FOUND=${Python3_Development_FOUND}"
)
message(FATAL_ERROR ${errmsg})
endif()
在 Linux 上使用 cmake-3.12.4-Linux-x86_64(从 cmake.org 下载)构建时,它工作正常,可以找到通过 apt-get 安装的 Python3 解释器和开发头文件/库。 (系统上也安装了 Python2,但我已经确认它找到的解释器是 Python 3。)
然而,在 Windows 10 上,它找到了开发头文件/库,但没有找到解释器,打印:
-- Selecting Windows SDK version 10.0.17763.0 to target Windows 10.0.14393.
-- Could NOT find Python3 (missing: Python3_EXECUTABLE Interpreter) (found version "3.6.6")
-- Python: version=3.6.6 interpreter=Python3_EXECUTABLE-NOTFOUND
CMake Error at hello-pyext/CMakeLists.txt:14 (message):
Python3 and/or development libs not found.
- Python3_FOUND=FALSE
- Python3_Development_FOUND=TRUE
我在 VS 2017 的 MinGW Bash 和 Developer Command Prompt 中得到了相同的结果,以及以下所有版本的 CMake:
-
cmake version 3.12.18081601-MSVC_2随 Visual Studio 2017 提供。 -
cmake-3.13.4-win64-x64从cmake.org下载。 -
cmake-3.14.0-rc3-win64-x64从cmake.org下载。 -
cmake-3.14.20190305-gc9ce4f-win64-x64(本次编辑的最新开发版本)从cmake.org下载
据我所知,我只使用过来自python.org 的标准安装程序来安装 Python。 “程序和功能”列出了已安装的 Python 3.4.4(64 位)、Python 3.6.6(64 位)和 Python Launcher。 py 启动器正确启动这两个,以及 python 本身在我的路径中:
C:\>py --version
Python 3.6.6
C:\>py -3.4 --version
Python 3.4.4
C:\>python --version
Python 3.6.6
C:\>python3 --version
'python3' is not recognized as an internal or external command,
operable program or batch file.
C:\>
我还检查了一位开发人员的机器,他通过 Anaconda 安装了 Python 3.5 作为他的主要 Python,以及从 python.org 安装的 3.6,并得到了相同的结果。
已弃用的 FindPythonInterp 似乎确实有效:
find_package(PythonInterp)
message("
PYTHONINTERP_FOUND=${PYTHONINTERP_FOUND}
PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE}
PYTHON_VERSION_STRING=${PYTHON_VERSION_STRING}
")
-- Found PythonInterp: C:/Program Files/Python36/python.exe (found version "3.6.6")
PYTHONINTERP_FOUND=TRUE
PYTHON_EXECUTABLE=C:/Program Files/Python36/python.exe
PYTHON_VERSION_STRING=3.6.6
我对 Windows 不太熟悉,所以我不确定从这里去哪里调试它。有谁知道为什么FindPython3 找不到解释器,或者我应该如何开始调试它(不仅仅是阅读FindPython3 的源代码)?
【问题讨论】:
标签: python windows cmake visual-studio-2017