Wrong environment Mac OS X boots

I have compiled a Python module using the native Qt4 library located in ~/opt/qt-4.6.0/

, but when I try to import that module, the dynamic libraries that are 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 to tell Python (also installed from MacPorts) to load the frameworks located in my directory ~/opt/qt-4.6.0/lib/

? I'm not sure which environment variables are changing.

+2


source to share


2 answers


Try setting DYLD_LIBRARY_PATH

to place your libraries in ~/opt/qt/...

front of the MacPorts libraries before calling python (look at ~/.profile

an example on how to do this, if you don't know, MacPorts does the same to put its libraries in DYLD_LIBRARY_PATH

). dyld

, the OS X dynamic linker uses DYLD_LIBRARY_PATH

to find libraries at load time (among other methods); For details see man dyld

.



+2


source


Okay, after Barry Work pointed me to dyld(1)

, the man page described a number of variables that I could set.

First hint at setting an environment variable DYLD_PRINT_LIBRARIES

so I could see which 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 did load first, as we suspected. Rereading the man page, the next thing we can try is change DYLD_FRAMEWORK_PATH

so that it knows where to look. I 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 in, we will try to import the vtk python module again:

$ python -c 'import vtk'
$

      

There is no way out this time. Bug fixed!

+2


source







All Articles