Install Caffe on Mac OS X 10.10

Take note, reference at:

Machine: Macbook Air 2013 OS X Yosemite Version 10.10.2 (core i7 1.7 GHz quad core)


GPU: Intel HD Graphics 5000 1536 MB (cannot use CUDA)

But you can install from NVIDIA CUDA


Installed on Mac


brew install pyenv
pyenv install anaconda-2.0.1
pyenv rehash
sudo pyenv local anaconda-2.0.1
sudo pyenv global anaconda-2.0.1

Update packages in anaconda

conda update conda
conda update anaconda

Check anaconda path

conda env list


brew update
brew tap homebrew/science
brew install opencv


Modify Formula for fix boost 1.55

cd /usr/local
git checkout a252214 /usr/local/Library/Formula/boost.rb
Set C++ library as libstdc++
Open formula for corresponded library
for x in snappy leveldb protobuf gflags glog szip boost boost-python lmdb homebrew/science/opencv; do brew edit $x; done

Put and modify these lines (below def install)

def install
+    ENV.append "CXXFLAGS", "-stdlib=libstdc++"
+    ENV.append "CFLAGS", "-stdlib=libstdc++"
+    ENV.append "LDFLAGS", "-stdlib=libstdc++ -lstdc++"
+    # The following is necessary because libtool likes to strip LDFLAGS:
+    ENV["CXX"] = "/usr/bin/clang++ -stdlib=libstdc++"


Modify Formula for fix boost 1.55.

brew edit boost-python

Modify as

   homepage ""
-  url ""
-  sha1 "f94bb008900ed5ba1994a1072140590784b9b5df"
+  url ''
+  sha1 'cef9a0cc7084b1d639e06cd3bc34e4251524c840'
+  revision 2
   head ""

Boost install

for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew uninstall $x; brew install --build-from-source --fresh -vd $x; done
brew uninstall protobuf; brew install --build-from-source --with-python --fresh -vd protobuf
brew uninstall boost
brew uninstall boost-python
brew install --build-from-source --fresh -vd boost boost-python

Finish preparation for dependencies


git clone
cd caffe
cp Makefile.config.example Makefile.config


Modify Makefile.config for my machine using CPU_ONLY option

# CPU-only switch (uncomment to build without GPU support).
- # CPU_ONLY := 1
+ CPU_ONLY := 1
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := /path/to/anaconda-2.0.1
 $(ANACONDA_HOME)/include/python2.7 \
 $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# We need to be able to find or .dylib.
# PYTHON_LIB := /usr/lib


ifeq ($(shell echo $(CUDA_VERSION) \< 7.0 | bc), 1)
 CXXFLAGS += -stdlib=libstdc++
 LINKFLAGS += -stdlib=libstdc++
+ ifneq ($(findstring 10.10, $(shell sw_vers -productVersion)),)
+ CXXFLAGS += -stdlib=libstdc++
+ LINKFLAGS += -stdlib=libstdc++
+ endif

 PATH setting

vim ~/.zshrc
# pyenv
export PYENV_ROOT="${HOME}/.pyenv"
if [ -d "${PYENV_ROOT}" ]; then
    export PATH=${PYENV_ROOT}/bin:$PATH
    eval "$(pyenv init -)"

# caffe
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:$HOME/.pyenv/versions/anaconda-2.0.1/lib:/usr/local/lib:/usr/lib
source ~/.zshrc

 Compile and Test

make all
make runtest
make pycaffe
make distribute

If there’s no problem, you can see the below message

[----------] Global test environment tear-down
[==========] 581 tests from 111 test cases ran. (14856 ms total)
[ PASSED ] 581 tests.


  • hdf5.h not found error → brew install hdf5
  • dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib error when run “make runtest”
    • brew install libpng
    • cp /usr/local/Cellar/libpng/1.6.18/lib/*.dylib /usr/local/lib/

Import caffe from Python

If the below error has occured

caffe Fatal Python error: PyThreadState_Get: no current thread

Try to re-install boost-python

brew uninstall boost-python
brew install --build-from-source --fresh -vd boost-python

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s