使用 cmake 查找正确的 Python 框架
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
~/.bash_profile
中添加以下内容至少可以暂时解决问题。显然,cmake 使用的 python 解释器和 python 框架之间的这种不一致是一个错误,希望在新版本中得到修复。
Adding the following in
~/.bash_profile
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.
我对 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.