Install caffe on Mac with El Capitan

Following the Caffe official instruction here:

There are a few steps needed to properly install and compile caffe on Mac with El Capitan, especially if you want to run python layer of caffe for some testing.

Always do check latest updates from Homebrew:

> brew update

Install python package via Homebrew:

> brew install python

To check your python installed correctly, type

> which python

you should get

> /usr/local/bin/python

install other packages:

> brew tap homebrew/science
> brew update
> brew install snappy leveldb gflags glog szip lmdb hdf5 numpy opencv graphviz
> brew install --build-from-source --with-python -vd protobuf

Now clone caffe repository from github

> git clone

And make your own Makefile.config

If you want to use python layer, make sure to uncomment:


Also, since we use HomeBrew installed python, we need make changes to PYTHON_INCLUDE and PYTHON_LIB in the file.

Otherwise, you will get

 >>> import caffe
   Segmentation fault: 11

After you build pycaffe and try to use it (so don’t do that! After failed building many times and searched online for solutions many times, I would say do it the correct way!)

Here is the correct way:
Check your python install location by type:

> pip show python 

and you will find something like:

Location: /usr/local/Cellar/python/[your python version]/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload

Now, you need to change your Makefile.config:

 PYTHON_INCLUDE=/usr/local/Cellar/python/[your python version]/Frameworks/Python.framework/Versions/2.7/include/python2.7


 PYTHON_LIB=/usr/local/Cellar/python/[your python version]/Frameworks/Python.framework/Versions/2.7/lib/

Now, you are ready to build caffe

> make all
> make test
> make runtest
> make pycaffe
> make distribute

Don’t forget set PYTHONPATH

> export PYTHONPATH=/your local caffe repository/caffe/python:$PYTHONPATH

Now, you are ready to test if your python layer is working or not:

> cd /your local caffe repository/caffe/python
> python

You should see something like:

usage: [-h] [--model_def MODEL_DEF]
                 [--pretrained_model PRETRAINED_MODEL]
                 [--crop_mode {list,selective_search}] [--gpu]
                 [--mean_file MEAN_FILE] [--input_scale INPUT_SCALE]
                 [--raw_scale RAW_SCALE] [--channel_swap CHANNEL_SWAP]
                 [--context_pad CONTEXT_PAD]
                 input_file output_file error: too few arguments

Congrats! You can start testing python layer of Caffe!

One thought on “Install caffe on Mac with El Capitan

Add yours

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 )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: