这是我使用的CMakeLists.txt文件的开头:
"When built with
我还与另一位开发人员的机器进行了对比,他将Python 3.5安装为Anaconda的主要Python,并从python.org上进行了3.6安装,结果也相同。
已弃用的“FindPythonInterp”似乎可以正常工作:
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()
"When built with
cmake-3.12.4-Linux-x86_64
(downloaded from cmake.org
) on Linux, it works fine, finding both the Python3 interpreter and development headers/libraries installed via apt-get
. (Python2 is also installed on the system, but I've confirmed that the interpreter it finds is the Python 3 one.)
然而,在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
我在MinGW Bash和Visual Studio 2017的开发者命令提示符中使用了以下版本的CMake,结果相同:
- 使用Visual Studio 2017安装程序自带的
cmake version 3.12.18081601-MSVC_2
- 从
cmake.org
下载的cmake-3.13.4-win64-x64
- 从
cmake.org
下载的cmake-3.14.0-rc3-win64-x64
- 从
cmake.org
下载的cmake-3.14.20190305-gc9ce4f-win64-x64
(此编辑时最新的开发版本)
我只记得我曾经使用过从python.org
下载的标准安装程序来安装Python。"程序和功能"列出了已安装的Python版本:Python 3.4.4 (64-bit)、Python 3.6.6 (64-bit)和Python Launcher。同时,py
启动器可以正确启动这两个版本的Python,并且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:\>
我还与另一位开发人员的机器进行了对比,他将Python 3.5安装为Anaconda的主要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
的源代码)?