0

I'm using Anaconda python on a Mac running OS X 10.11 El Capitan.

I'm trying to use pycaffe in iPython, but importing it (import caffe) fails with the error

ImportError: dlopen(/Users/.../Documents/caffe-master/python/caffe/_caffe.so, 2): Library not loaded: @rpath/libcudart.7.5.dylib
  Referenced from: /Users/.../Documents/caffe-master/python/caffe/_caffe.so
  Reason: image not found

While iPython can't import caffe, doing so in 'ordinary' python works.

Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import caffe
>>> caffe.Net
<class 'caffe._caffe.Net'>

I should also mention that I'm using CUDA 7.5, and although I can't see which version of caffe I have (downloaded zip) it was done from the master branch on September 17 2015.

The actions I took for 'ordinary' python to be able to import caffe was to add the following to ~/.bash_profile

# added pycaffe path
export PYTHONPATH="/Users/.../Documents/caffe-master/python:$PYTHONPATH"

# needed to import pycaffe in python
export DYLD_FALLBACK_LIBRARY_PATH='/usr/local/cuda/lib:/anaconda/lib:/usr/local/lib:/usr/lib:/opt/intel/lib:/opt/intel/mkl/lib'

iPython is reading the PYTHONPATH set in .bash_profile since it will give ImportError: No module named caffe if the export PYTHONPATH=... line is commented out. But for some reason it doesn't find the DYLD_FALLBACK_LIBRARY_PATH, which 'ordinary' python does.

Any ideas on what might be wrong?

Skeppet
  • 931
  • 1
  • 9
  • 17

1 Answers1

0

Ok, so it turns out that the main issue was that due to the new feature called SIP (System Integrity Protection) in El Capitan, that prevents DYLD_FALLBACK_LIBRARY_PATH from being set. This is a feature that is supposed to provide extra protection against root attacks on Mac OSX.

To disable SIP:

  • Restart computer in recovery mode by holding in cmd-R when starting up.
  • Open a terminal window (under Utilities in the top menu).
  • Enter csrutil disable to turn SIP off (and csrutil enable to turn it back on).
  • Restart computer from Apple symbol in the manu.

This solved the issue for me. For more info: MacWorld article on SIP, Caffe user mailing list.

Skeppet
  • 931
  • 1
  • 9
  • 17