问题
I am using Python 2.7 and am trying to import graph_tool, and it seems that my libboost_thread-mt.dylib is located in /opt/local/lib rather than /usr/local/lib.
If I start an X11 terminal and type in
export DYLD_LIBRARY_PATH='/opt/local/lib'
then Python successfully imports graph_tool. On the other hand, if I add
export DYLD_LIBRARY_PATH='/opt/local/lib':$DYLD_LIBRARY_PATH
to ~/.bash_profile
, X11 stops working. I am really confused as to what is happening here. Why can't I add /opt/local/lib
to $DYLD_LIBRARY_PATH
permanently without destroying my computer?
Any help is much appreciated. Thanks!
回答1:
Trying to permanently set DYLD_LIBRARY_PATH
is almost always an indication that you are doing something wrong. On OS X, well-designed components embed absolute paths or RPATH
s to shared libraries so that setting environment variables to override library search paths should seldom be needed.
Since you show path /opt/local/lib
, I assume you are using MacPorts since this is its default installation path. If you are not able to import a MacPorts-installed Python package, chances are you are using the wrong Python instance. MacPorts installs all Python packages to its own Python interpreter. So, if you installed the Python 2.7 version with:
sudo port install py27-graph-tool
MacPorts would also have installed, if not installed already, its own python2.7
in /opt/local/bin
. Try running that instead and doing the import there.
/opt/local/bin/python2.7
If you haven't already, you should add /opt/local/bin
to your shell PATH in a shell startup file, like ~/.profile
, so you don't need to always type /opt/local/bin
.
来源:https://stackoverflow.com/questions/24963317/permanently-adding-to-dyld-library-path-on-mac-causes-x11-errors