OS X cmake找不到PythonLibs 3.4

时间:2015-05-26 23:23:03

标签: python macos python-3.x cmake

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)

得到:

-- 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"

的CMakeLists.txt:

set(Python_ADDITIONAL_VERSIONS 3.4)
FIND_PACKAGE(PythonInterp 3.4 REQUIRED)
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)

得到:

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


然后我将其添加到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)

甚至将目录复制到/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)

看起来很奇怪。

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您需要在“LD_LIBRARY_PATH”环境变量中添加库的路径。通过这种方式,CMake将知道在哪里寻找它们。多个python安装或安装在非标准位置时可能会发生这种情况。这应该解决它:

export LD_LIBRARY_PATH=/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib:$LD_LIBRARY_PATH

CMake命令“INCLUDE_DIRECTORIES”仅适用于标题(aka。/ usr / include)。

- >如果我的解决方案不起作用,请确保安装了python-devel:how to install python-devel in Mac OS?