加载了错误的 Mac OS X 框架
我使用自己的 Qt4 库编译了一个 Python 模块,该库位于 ~/opt/qt-4.6.0/
中, 但是当我尝试导入该模块时,加载的动态库来自我的 MacPorts Qt4 安装。
$ /opt/local/bin/python2.6
>>> import vtk
objc[58041]: Class QMacSoundDelegate is implemented in both /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui and /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui. Using implementation from /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui.
objc[58045]: Class QCocoaColorPanelDelegate is implemented in both /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui and /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui. Using implementation from /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui.
[... more output like above ...]
>>>
有没有办法告诉 Python(也从 MacPorts 安装)加载位于我的 ~/opt/qt-4.6.0/lib/
目录中的框架?我不确定要更改哪些环境变量。
I've compiled a Python module using my own Qt4 library located in ~/opt/qt-4.6.0/
,
but when I try to import that module, the dynamic libraries that get loaded are from my MacPorts Qt4 installation.
$ /opt/local/bin/python2.6
>>> import vtk
objc[58041]: Class QMacSoundDelegate is implemented in both /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui and /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui. Using implementation from /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui.
objc[58045]: Class QCocoaColorPanelDelegate is implemented in both /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui and /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui. Using implementation from /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui.
[... more output like above ...]
>>>
Is there a way of telling Python (also installed from MacPorts) to load the frameworks located in my ~/opt/qt-4.6.0/lib/
directory? I'm not sure what environment variables to change.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,在 Barry Wark 向我指出 dyld(1) 后,手册页描述了许多我可以设置的变量。
第一个提示来自设置环境变量 DYLD_PRINT_LIBRARIES,这样我就可以看到正在加载哪些库。
啊,所以 qt4-mac 的框架确实是先加载的,正如我们所怀疑的那样。重新阅读手册页,我们接下来可以尝试的是更改 DYLD_FRAMEWORK_PATH 以便它知道在哪里查找。我现在将此行添加到我的
~/.bash_profile
的末尾,重新登录后,我们尝试再次导入 vtk python 模块:
这次没有输出。问题已解决!
Ok, after Barry Wark pointed me to
dyld(1)
, the man page described a number of variables that I could set.The first hint came from setting the environment variable
DYLD_PRINT_LIBRARIES
, so I could see what libraries were being loaded.Ah, so the frameworks for qt4-mac were indeed being loaded first, just as we suspected. Rereading the man page, the next thing we can try is changing the
DYLD_FRAMEWORK_PATH
so that it knows where to look. I now added this line to the end of my~/.bash_profile
and after logging back in, we try importing the vtk python module again:
There's no output this time. Issue fixed!
在调用 python 之前,尝试设置 DYLD_LIBRARY_PATH 将您的库放在 MacPorts 库之前的 ~/opt/qt/... 中(看看
~/如果您不知道,请参阅 .profile
示例了解如何执行此操作;MacPorts 会执行完全相同的操作将其库放在DYLD_LIBRARY_PATH
上)。dyld
,OS X 动态链接器使用DYLD_LIBRARY_PATH
在加载时查找库(以及其他方法);请参阅man dyld
了解更多信息。Try setting the
DYLD_LIBRARY_PATH
to put your libraries in~/opt/qt/...
before the MacPorts' libraries before invoking python (take a look at~/.profile
for an example of how to do this if you don't know; MacPorts does the exact same thing to put its libraries on theDYLD_LIBRARY_PATH
).dyld
, the OS X dynamic linker usesDYLD_LIBRARY_PATH
to find libraries at load time (among other methods); Seeman dyld
for more info.