使用 cmake 查找正确的 Python 框架

发布于 2024-08-10 10:49:08 字数 860 浏览 1 评论 0原文

我在 Snow Leopard 计算机上使用 macports 版本的 python,并使用 cmake 为其构建跨平台扩展。我使用 CMakeLists.txt 中的以下命令搜索系统上的 python 解释器和库

include(FindPythonInterp)
include(FindPythonLibs  )

但是,虽然 cmake 在 /opt/local/bin 中识别了正确的解释器,但它尝试链接到错误的框架- 即系统Python框架。

-- Found PythonInterp: /opt/local/bin/python2.6
-- Found PythonLibs: -framework Python

这会导致以下运行时错误

Fatal Python error: Interpreter not initialized (version mismatch?)

一旦我用 /opt/local/Library/Frameworks/Python.framework/Python 替换 -framework Python ,事情似乎就会按预期工作。

如何使 cmake 链接到 中找到的正确 Python 框架

/opt/local/Library/Frameworks/Python.framework/Python

而不是 中的系统框架

/System/Library/Frameworks/Python.framework/Python

I am using the macports version of python on a Snow Leopard computer, and using cmake to build a cross-platform extension to it. I search for the python interpreter and libraries on the system using the following commands in CMakeLists.txt

include(FindPythonInterp)
include(FindPythonLibs  )

However, while cmake identified the correct interpreter in /opt/local/bin, it tries to link against the wrong framework - namely the system Python framework.

-- Found PythonInterp: /opt/local/bin/python2.6
-- Found PythonLibs: -framework Python

And this causes the following runtime error

Fatal Python error: Interpreter not initialized (version mismatch?)

As soon as I replace -framework Python with /opt/local/Library/Frameworks/Python.framework/Python things seem to work as expected.

How can I make cmake link against the correct Python framework found in

/opt/local/Library/Frameworks/Python.framework/Python

rather than the system one in

/System/Library/Frameworks/Python.framework/Python

?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

肥爪爪 2024-08-17 10:49:08

~/.bash_profile 中添加以下内容

export DYLD_FRAMEWORK_PATH=/opt/local/Library/Frameworks

至少可以暂时解决问题。显然,cmake 使用的 python 解释器和 python 框架之间的这种不一致是一个错误,希望在新版本中得到修复。

Adding the following in ~/.bash_profile

export DYLD_FRAMEWORK_PATH=/opt/local/Library/Frameworks

fixes the problem at least temporarily. Apparently, this inconsistency between the python interpreter and the python framework used by cmake is a bug that should be hopefully fixed in the new version.

月亮是我掰弯的 2024-08-17 10:49:08

我对 CMake 不太熟悉,但是使用 Apple 版本的 gcc/ld,您可以传递 -F 标志来指定新的框架搜索路径。例如,-F/opt/local/Library/Frameworks将在MacPorts的frameworks目录中搜索。如果您可以使用 CMake 指定这样的标志,它可能会解决您的问题。

I am not intimately familiar with CMake, but with the Apple version of gcc/ld, you can pass the -F flag to specify a new framework search path. For example, -F/opt/local/Library/Frameworks will search in MacPorts' frameworks directory. If you can specify such a flag using CMake, it may solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文