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?

4

1 回答 1

0

好的,事实证明,主要问题是由于 El Capitan 中称为 SIP(​​系统完整性保护)的新功能,它阻止DYLD_FALLBACK_LIBRARY_PATH了设置。该功能旨在为 Mac OSX 上的根攻击提供额外保护。

要禁用 SIP:

  • 启动时按住 cmd-R 以恢复模式重新启动计算机。
  • 打开一个终端窗口(在顶部菜单的实用程序下)。
  • 输入csrutil disable以关闭 SIP(​​并csrutil enable重新打开)。
  • 从手册中的 Apple 符号重新启动计算机。

这为我解决了这个问题。更多信息:关于 SIP 的 MacWorld 文章Caffe 用户邮件列表

于 2015-10-23T08:13:10.113 回答