2

我已经使用位于 中的我自己的 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/目录中的框架?我不确定要更改哪些环境变量。

4

2 回答 2

2

在调用 python 之前,尝试DYLD_LIBRARY_PATH将您的库设置在~/opt/qt/...MacPorts 的库之前(~/.profile如果您不知道,请查看如何执行此操作的示例;MacPorts 将其库放在DYLD_LIBRARY_PATH. dyld,OS X 动态链接器用于DYLD_LIBRARY_PATH在加载时查找库(以及其他方法);有关man dyld更多信息,请参阅。

于 2009-09-04T20:18:04.060 回答
2

好的,在 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 ...]
$

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!

于 2009-09-04T21:33:33.393 回答