加载了错误的 Mac OS X 框架

发布于 2024-08-04 02:45:46 字数 907 浏览 7 评论 0原文

我使用自己的 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 技术交流群。

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

发布评论

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

评论(2

短叹 2024-08-11 02:45:46

好的,在 Barry Wark 向我指出 dyld(1) 后,手册页描述了许多我可以设置的变量。

第一个提示来自设置环境变量 DYLD_PRINT_LIBRARIES,这样我就可以看到正在加载哪些库。

$ DYLD_PRINT_LIBRARIES=1 python -c 'import vtk'
[... snip ...]
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui
dyld: loaded: /opt/local/lib/libpng12.0.dylib
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtSql.framework/Versions/4/QtSql
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtCore.framework/Versions/4/QtCore
[... snip ...]
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtSql.framework/Versions/4/QtSql
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtCore.framework/Versions/4/QtCore
[... snip ...]
$

啊,所以 qt4-mac 的框架确实是先加载的,正如我们所怀疑的那样。重新阅读手册页,我们接下来可以尝试的是更改 DYLD_FRAMEWORK_PATH 以便它知道在哪里查找。我现在将此行添加到我的 ~/.bash_profile 的末尾

export DYLD_FRAMEWORK_PATH="${HOME}/opt/qt-4.6.0/lib:${DYLD_FRAMEWORK_PATH}"

,重新登录后,我们尝试再次导入 vtk python 模块:

$ python -c 'import vtk'
$

这次没有输出。问题已解决!

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.

$ DYLD_PRINT_LIBRARIES=1 python -c 'import vtk'
[... snip ...]
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/QtGui
dyld: loaded: /opt/local/lib/libpng12.0.dylib
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtSql.framework/Versions/4/QtSql
dyld: loaded: /opt/local/libexec/qt4-mac/lib/QtCore.framework/Versions/4/QtCore
[... snip ...]
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtGui.framework/Versions/4/QtGui
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtSql.framework/Versions/4/QtSql
dyld: loaded: /Users/luis/opt/qt-4.6.0/lib/QtCore.framework/Versions/4/QtCore
[... snip ...]
$

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

export DYLD_FRAMEWORK_PATH="${HOME}/opt/qt-4.6.0/lib:${DYLD_FRAMEWORK_PATH}"

and after logging back in, we try importing the vtk python module again:

$ python -c 'import vtk'
$

There's no output this time. Issue fixed!

走野 2024-08-11 02:45:46

在调用 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 the DYLD_LIBRARY_PATH). dyld, the OS X dynamic linker uses DYLD_LIBRARY_PATH to find libraries at load time (among other methods); See man dyld for more info.

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