简体   繁体   English

在 Mac OS X 上将 Python3 与 CMake 链接

[英]Link Python3 with CMake on Mac OS X

I am using CMake.我正在使用 CMake。 I want to link Python3 libraries to my project.我想将 Python3 库链接到我的项目。 I installed Python3 by homebrew, and write CMakeLists.txt like this:我通过自制软件安装了 Python3,并像这样编写CMakeLists.txt

find_package(PythonLibs 3.6 REQUIRED)

But then it gave me an error:但后来它给了我一个错误:

Could NOT find PythonLibs: Found unsuitable version "2.7.10", but required
is at least "3.6" (found /usr/lib/libpython2.7.dylib)

This error happens on Mac OS X. Could anybody tell me how to solve it?这个错误发生在 Mac OS X 上。有人能告诉我如何解决吗? Thanks.谢谢。

I had this same error on Mac OSX and installing python3 with Homebrew did not fix it.我在 Mac OSX 上遇到了同样的错误,用 Homebrew 安装 python3 没有修复它。 Following the advice found on this post , cleaning my build directory did fix the problem and Python3.6 was found.按照这篇文章中的建议,清理我的构建目录确实解决了问题,并找到了 Python3.6。

I have solved this problem so I am answering this question by myself.我已经解决了这个问题,所以我自己来回答这个问题。

Python installed by Homebrew cannot be found by CMake. CMake 找不到 Homebrew 安装的 Python。 However, you can build Python from source and make install it, then CMake can find this.但是,您可以从源代码构建 Python 并进行安装,然后 CMake 可以找到它。

更简单的解决方案 - 您可以从 python 官方网站下载“macOS 64 位安装程序”并安装它。

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

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