OS X cmake找不到PythonLibs 3.4

isk*_*ovt 10 python macos cmake python-3.x

python和python3通过Homebrew安装在OS X Yosemite中,但是cmake无法找到PythonLibs 3,只有2:


的CMakeLists.txt:

set(Python_ADDITIONAL_VERSIONS 3.4)
FIND_PACKAGE(PythonInterp REQUIRED)
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)
Run Code Online (Sandbox Code Playgroud)

得到:

-- Found PythonInterp: /usr/local/bin/python3.4 (found suitable version "3.4.3", minimum required is "3.4")
-- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6"
Run Code Online (Sandbox Code Playgroud)

的CMakeLists.txt:

set(Python_ADDITIONAL_VERSIONS 3.4)
FIND_PACKAGE(PythonInterp 3.4 REQUIRED)
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)
Run Code Online (Sandbox Code Playgroud)

得到:

Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is at least "3.4" (found PYTHON_LIBRARY-NOTFOUND)
Run Code Online (Sandbox Code Playgroud)


然后我将其添加到cmake列表:

INCLUDE_DIRECTORIES(/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib)
INCLUDE_DIRECTORIES(/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/include/python3.4m)
Run Code Online (Sandbox Code Playgroud)

甚至将目录复制到/usr/lib,然后得到:

Could NOT find PythonLibs: Found unsuitable version "2.7.6", but required
is at least "3.4" (found /usr/lib/libpython3.4.dylib)
Run Code Online (Sandbox Code Playgroud)

看起来很奇怪.

l'L*_*L'l 1

看来您的CMake配置中找到了正确的 Python 版本,但还需要设置库的位置。根据您的安装/配置,库的位置可能会有所不同,但在配置中您需要类似的内容:

PYTHON_LIBRARIES=/Library/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib
PYTHON_INCLUDE_DIR=/Library/Frameworks/Python.framework/Versions/3.4/include/python3.4m
Run Code Online (Sandbox Code Playgroud)

http://www.cmake.org/cmake/help/v3.0/module/FindPythonLibs.html