Skip to content

Instantly share code, notes, and snippets.

Last active September 22, 2021 11:45
Show Gist options
  • Save doctorpangloss/f8463bddce2a91b949639522ea1dcbe4 to your computer and use it in GitHub Desktop.
Save doctorpangloss/f8463bddce2a91b949639522ea1dcbe4 to your computer and use it in GitHub Desktop.
Installing Caffe on Mac 10.11.5 and later in the 10.11 series, and 10.12.1 and later in the 10.12 series
# Install brew
/usr/bin/ruby -e "$(curl -fsSL"
# Apple hides old versions of stuff at
# Install the latest XCode (8.0).
# We used to install the XCode Command Line Tools 7.3 here, but that would just upset the most recent versions of brew.
# So we're going to install all our brew dependencies first, and then downgrade the tools. You can switch back after
# you have installed caffe.
# Install CUDA toolkit 8.0 release candidate
# Register and download from
# or this path from
# Select both the driver and the toolkit, no documentation necessary
# Install the experimental NVIDIA Mac drivers
# Download from
# Install cuDNN v5 for 8.0 RC or use the latest when it's available
# Register and download from
# or this path:
# extract to the NVIDIA CUDA folder and perform necessary linking
# into your /usr/local/cuda/lib and /usr/local/cuda/include folders
# You will need to use sudo because the CUDA folder is owned by root
sudo tar -xvf ~/Downloads/cudnn-8.0-osx-x64-v5.0-ga.tar /Developer/NVIDIA/CUDA-8.0/
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.dylib /usr/local/cuda/lib/libcudnn.dylib
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn.5.dylib /usr/local/cuda/lib/libcudnn.5.dylib
sudo ln -s /Developer/NVIDIA/CUDA-8.0/lib/libcudnn_static.a /usr/local/cuda/lib/libcudnn_static.a
sudo ln -s /Developer/NVIDIA/CUDA-8.0/include/cudnn.h /usr/local/cuda/include/cudnn.h
# Install the brew dependencies
# Do not install python through brew. Only misery lies there
# We'll use the versions repository to get the right version of boost and boost-python
# We'll also explicitly upgrade libpng because it's out of date
# Do not install numpy via brew. Your system python already has it.
brew install -vd snappy leveldb gflags glog szip lmdb
brew install hdf5 opencv
brew upgrade libpng
brew tap homebrew/science
brew tap homebrew/versions
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost159 boost-python159
# Clone the caffe repo
cd ~/Documents
git clone
# Setup Makefile.config
# You can download mine directly from here, but I'll explain all the selections
# For XCode 7.3:
# For XCode 8.0 and later (Sierra):
# First, we'll enable cuDNN
# USE_CUDNN := 1
# In order to use the built-in Accelerate.framework, you have to reference it.
# Astonishingly, nobody has written this anywhere on the internet.
# BLAS := atlas
# If you use El Capitan (10.11), we'll use the 10.11 sdk path for vecLib:
# BLAS_INCLUDE := /Applications/
# Otherwise (10.12), let's use the 10.12 sdk path:
# BLAS_INCLUDE := /Applications/
# BLAS_LIB := /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A
# Configure to use system python and system numpy
# PYTHON_INCLUDE := /System/Library/Frameworks/Python.framework/Headers \
# /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include
# PYTHON_LIB := /System/Library/Frameworks/Python.framework/Versions/2.7/lib
# Configure to enable Python layers. Some projects online need this
curl -o Makefile.config
# Download the XCode Command Line Tools for 7.3, since NVIDIA does not yet support Xcode 8.0's tools
# Now, choose those tools instead
sudo xcode-select --switch /Library/Developer/CommandLineTools
# Go ahead and build.
cd caffe
make -j8 all
# To get python going, first we need the dependencies
# On a super-clean Mac install, you'll need to easy_install pip.
sudo -H easy_install pip
# Now, we'll install the requirements system-wide. You may also muck about with a virtualenv.
# Astonishingly, --user is not better known.
pip install --user -r python/requirements.txt
# Go ahead and run pytest now. Horrible @rpath warnings which can be ignored.
make -j8 pytest
# Now, install the package
# Make the distribution folder
make distribute
# Install the caffe package into your local site-packages
cp -r distribute/python/caffe ~/Library/Python/2.7/lib/python/site-packages/
# Finally, we have to update references to where the libcaffe libraries are located.
# You can see how the paths to libraries are referenced relatively
# otool -L ~/Library/Python/2.7/lib/python/site-packages/caffe/
# Generally, on a System Integrity Protection -enabled (SIP-enabled) Mac this is no good.
# So we're just going to change the paths to be direct
cp distribute/lib/ ~/Library/Python/2.7/lib/python/site-packages/caffe/
install_name_tool -change @rpath/ ~/Library/Python/2.7/lib/python/site-packages/caffe/ ~/Library/Python/2.7/lib/python/site-packages/caffe/
# Verify that everything works
# start python and try to import caffe
python -c 'import caffe'
# If you got this far without errors, congratulations, you installed Caffe on a modern Mac OS X
Copy link

My MacBook's GPU is Intel Iris Graphics 6100, not cuda-based, so cannot run caffe with GPU on my mac? And there is no need to install cuda toolkit?

Copy link

chengsam commented Sep 15, 2017

@ShivaliGoel Run the command in the caffe directory, i.e. cd caffe

Copy link

adelaidepan commented Dec 20, 2017

raffaelladeMacBook-Pro:Documents raffaella$ make -j8 all make: *** No rule to make target all'. Stop.

What should I do? I got this error.

Copy link

haemi commented Jan 5, 2018

brew tap homebrew/versions - deprecated
brew tap homebrew/science - deprecated

what to use instead?

Copy link

@adelaidepan Run the command in the caffe directory, i.e., cd caffe.

Copy link

@joyzhou28 You cannot run caffe with GPU on your Mac, and you do not need to install CUDA toolkit. Download the latest binary from their website if you don't need CUDA support.

Copy link

AHEADer commented Mar 20, 2018

dropbox failed....

Copy link

Is it possible on Mac 10.13 series?

Copy link

triple-tam commented Dec 21, 2018

Copy link

@joyzhou28 You cannot run caffe with GPU on your Mac, and you do not need to install CUDA toolkit. Download the latest binary from their website if you don't need CUDA support.

I also have a MacOS 10.12 but with no Nvidia graphics driver (I have Intel Iris 1600 instead). So if I understand your comment correctly, I won't be able to install CUDA toolkit on my Mac. What do you mean by latest binary though? Can you provide a link? What does this binary do?

And if I download the binary instead of the CUDA toolkit, how does this change the commands I should run from your file? Thank you!

Copy link

Hi, when I ran make -j8 all, I got following errors"
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [.build_release/lib/] Error

Please help. Thank you.

I ran into the same issue. I have no idea what this error is about. Can someone please help. Thank you.

Copy link

Hi, you're makefile config is broken:

dropbox is giving 404

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment