OS X cmake 找不到 PythonLibs 3.4
Posted
技术标签:
【中文标题】OS X cmake 找不到 PythonLibs 3.4【英文标题】:OS X cmake can't find PythonLibs 3.4 【发布时间】:2015-08-08 20:10:11 【问题描述】: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)
这看起来很奇怪。
【问题讨论】:
在 Windows 上 cmake 出现同样的问题,特别是这一行是一个愚蠢的错误消息:(found suitable version "3.4.3", minimum required is "3.4")
【参考方案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
http://www.cmake.org/cmake/help/v3.0/module/FindPythonLibs.html
【讨论】:
它看起来不是一个通用的解决方案,但它工作得很好。现在我决定使用 python3 setuptools 而不是 cmake。【参考方案2】:您需要在“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”仅适用于标头(又名/usr/include)。
-> 如果我的解决方案不起作用,请确保您已安装 python-devel:how to install python-devel in Mac OS?
【讨论】:
以上是关于OS X cmake 找不到 PythonLibs 3.4的主要内容,如果未能解决你的问题,请参考以下文章