Alex Pearwin

Python and ROOT on OS X

This post has been archived. It's pretty old and likely concerns topics that are avoidable by using more modern tools and techniques. The original text is preserved below for posterity but it may no longer be relevant or correct.

I don’t find myself using ROOT much on my home machine, but when I do there’s usually something broken.

In this case, it was when trying to use PyROOT, a ROOT interface for Python, that this error made my day:

>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/root/lib/ROOT.py", line 85, in <module>
    import libPyROOT as _root
ImportError: dlopen(/usr/local/root/lib/libPyROOT.so, 2): Library not loaded: @rpath/libRIO.so
  Referenced from: /usr/local/root/lib/libPyROOT.so
  Reason: image not found

This is using the install as documented in a previous post.

The problem is that the library Python loads can’t find another library it needs. To fix this, the DYLD_LIBRARY_PATH variable needs to be set:

export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH

This can be executed directly in the shell or placed in a .bashrc-type file.

Caveat

This solution is not without fault. Namely, whenever one runs a command with sudo, the following warning appears:

dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid

This is a well known issue with OS X 10.8 (Mountain Lion), complete with a bug report.

At least one workaround is available, but for now I put up with the message in the shell I want to use PyROOT in, manually setting DYLD_LIBRARY_PATH when needed.