简体   繁体   English

OS X cmake找不到PythonLibs 3.4

[英]OS X cmake can't find PythonLibs 3.4

python and python3 are installed in OS X Yosemite via Homebrew, but cmake fails to find PythonLibs 3, only 2: python和python3通过Homebrew安装在OS X Yosemite中,但是cmake无法找到PythonLibs 3,只有2:


CMakeLists.txt: 的CMakeLists.txt:

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

get: 得到:

-- 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: 的CMakeLists.txt:

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

get: 得到:

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


Then I added this to cmake lists: 然后我将其添加到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)

and even copied that directories to /usr/lib , and then got: 甚至将该目录复制到/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)

that looks weird. 看起来很奇怪。

It appears the correct version of Python is found in your CMake configuration, but locations of the libraries also needs to be set. 看起来在您的CMake配置中找到了正确的Python版本,但是还需要设置库的位置。 Depending on your installation/configuration the location of the libraries might vary, although in the configuration you'll want something similar: 根据您的安装/配置,库的位置可能会有所不同,但在配置中您需要类似的东西:

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 http://www.cmake.org/cmake/help/v3.0/module/FindPythonLibs.html

You need to add the path to the libraries in your "LD_LIBRARY_PATH" environment variable. 您需要在“LD_LIBRARY_PATH”环境变量中添加库的路径。 In this way, CMake will know where to look for them. 通过这种方式,CMake将知道在哪里寻找它们。 This may happen with multiple python installations or when it is installed in a non standard location. 多个python安装或安装在非标准位置时可能会发生这种情况。 This should solve it: 这应该解决它:

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

The CMake command "INCLUDE_DIRECTORIES" is only for headers (aka. /usr/include). CMake命令“INCLUDE_DIRECTORIES”仅用于标题(aka。/ usr / include)。

-> If my solution doesn't work, make sure you have python-devel installed: how to install python-devel in Mac OS? - >如果我的解决方案不起作用,请确保安装 python-devel: 如何在Mac OS中安装python-devel?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM