Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Deepdream installation
#!/usr/bin/env bash

# Assuming OS X Yosemite 10.10.4

# Install XCode and command line tools
# See
# See
xcode-select --install

# Install the Homebrew package manager if you don't already use it; see source
ruby -e "$(curl -fsSL"

# Install homebrew cask
brew install caskroom/cask/brew-cask

# Install Python 2.7 and pip
brew install python pip

# Install Cuda 7
brew cask install cuda

# Optionally install cuDNN from which requries
# 1) Registering for an NVIDIA account, accepting an end-user-license-agreement
# 2) Downloading and extracting a tar.gz archive
# 3) Copying lib* files to /usr/local/cuda/lib and cudnn.h to /usr/local/cuda/include
# robertsdionne:~/$ ls /usr/local/cuda/lib/*dnn*
# /usr/local/cuda/lib/libcudnn.6.5.dylib /usr/local/cuda/lib/libcudnn_static.a
# /usr/local/cuda/lib/libcudnn.dylib
# robertsdionne:~/$ ls /usr/local/cuda/include/*dnn*
# /usr/local/cuda/include/cudnn.h

# Install dependencies; see
brew install --fresh -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv
# with Python pycaffe needs dependencies built from source
brew install --build-from-source --with-python --fresh -vd protobuf
# We need boost{,-python}-1.57.0 due to a bug in 1.58.0 on Yosemite 10.10.4
brew install --build-from-source --fresh -vd \ \

# Clone caffe
git clone
cd caffe

# Install python dependencies
pip install --requirement python/requirements.txt

# Adjust Makefile.config
cp Makefile.config.example Makefile.config

########## Make the following adjustments to Makefile.config:
diff --git a/Makefile.config b/../caffe/Makefile.config
index a873502..c6806c2 100644
--- a/Makefile.config
+++ b/../caffe/Makefile.config
@@ -2,7 +2,7 @@
 # Contributions simplifying and improving our build system are welcome!
 # cuDNN acceleration switch (uncomment to build with cuDNN).
-# USE_CUDNN := 1
+# USE_CUDNN := 1  ########### Keep it like this to disable cuDNN
+USE_CUDNN := 1    ########### Make it like this to enable cuDNN
 # CPU-only switch (uncomment to build without GPU support).
 # CPU_ONLY := 1
@@ -34,7 +34,7 @@ BLAS := atlas
 # Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
 # Leave commented to accept the defaults for your choice of BLAS
 # (which should work)!
-# BLAS_INCLUDE := /path/to/your/blas
+BLAS_INCLUDE := /Applications/
 # BLAS_LIB := /path/to/your/blas
 # Homebrew puts openblas in a directory that is not on the standard search path
@@ -48,8 +48,8 @@ BLAS := atlas
 # 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
+PYTHON_INCLUDE := /usr/local/lib/python2.7/site-packages/numpy/core/include/ \
+		/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/include/python2.7/
 # Anaconda Python distribution is quite popular. Include path:
 # Verify anaconda location, sometimes it's in root.
 # ANACONDA_HOME := $(HOME)/anaconda
@@ -58,7 +58,9 @@ PYTHON_INCLUDE := /usr/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
+PYTHON_LIB := /usr/local/lib/python2.7 \
+		/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/ \
+		/usr/local/lib/python2.7/site-packages/numpy/lib
 # Homebrew installs numpy in a non standard path (keg only)
########## Make the following adjustments to Makefile:
diff --git a/Makefile b/../caffe/Makefile
index e4e66df..8babaf8 100644
--- a/Makefile
+++ b/../caffe/Makefile
@@ -335,7 +335,7 @@ else
 			LDFLAGS += -framework Accelerate
 			BLAS_INCLUDE ?= /System/Library/Frameworks/vecLib.framework/Versions/Current/Headers/
-			LDFLAGS += -framework vecLib
+			LDFLAGS += -framework Accelerate
# Build caffe
make all -j8; make pycaffe -j8

# Package caffe
make distribute

# Set your environment variables for success
export PYTHONPATH="$HOME/caffe/distribute/python:$PYTHONPATH"
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/lib:$HOME/caffe/distribute/lib:$DYLD_FALLBACK_LIBRARY_PATH

# Clone deepdream
cd ..
git clone
cd deepdream

# Install python requirements
pip install numpy scipy scikit-image pillow ipython[notebook]

# Start IPython Notebook and select dream.ipynb
ipython notebook dream.ipynb

Thank you! working through it now.

Since line 7 uses cask, you could also add brew install caskroom/cask/brew-cask before that?

grrowl commented Jul 4, 2015

+1 to brew install caskroom... I didn't have cask installed.

Is there a typo on line 82? (//usr/local/Cellar/python/...)

I got as far as line 108 (make all -j8; make pycaffe -j8), but fail with heaps of fatal error: 'cudnn.h' file not found errors. ended up on this but am going to reinstall from this docker image instead

Hi, I dont know anything about coding and stuff like that but I'd like to know how to run this deep dream program. I downloaded ipython and caffe but I dont get the thing. Can someone help me ?

porkroll commented Jul 4, 2015

I think I've installed all the components correctly.. well, not sure, but it started a 'notebook' and now I just can't figure out where/how to load and process an image. help!?

edit: noticed the last line after I run the 'ipython notebook dream.ipynb' comes back: 'Notebook dream.ipynb is not trusted
[I 17:34:33.956 NotebookApp] Kernel started: 4ce27e75-495d-41a2-8002-a056120dab98'

not trusted bad?

forresto commented Jul 4, 2015

Line 105 make all -j8; make pycaffe -j8 the 8 should = the number of cores on your CPU.

I get an error when I try to import caffe (both in iPython notebook and interactive python shell).
I suppose it's somehow related to errors I get when running dream.ipynb:

python/caffe/_caffe.cpp:10:10: fatal error: 'numpy/arrayobject.h' file not found
#include <numpy/arrayobject.h>
1 error generated.

numpy is installed and can be freely imported.
Any ideas?

I am getting two errors when I run make all -j8; make pycaffe -j8 : make all -j8;

PROTOC src/caffe/proto/caffe.proto
CXX src/caffe/blob.cpp
CXX src/caffe/common.cpp
make: protoc: No such file or directory
make: *** [.build_release/src/caffe/proto/] Error 1
make: *** Waiting for unfinished jobs....
CXX src/caffe/data_transformer.cpp
CXX src/caffe/internal_thread.cpp
In file included from src/caffe/common.cpp:5:
In file included from ./include/caffe/common.hpp:19:
In file included from ./include/caffe/util/device_alternate.hpp:40:
./include/caffe/util/cudnn.hpp:5:10: fatal error: 'cudnn.h' file not found

include <cudnn.h>

Has anyone been able to figure out how to resolve either the make: protoc: No such file or directory or fatal error: 'cudnn.h' file not found errors?


robertsdionne commented Jul 5, 2015

If you are missing protoc, you might have skipped this step:

brew install --build-from-source --with-python --fresh -vd protobuf

To resolve cudnn.h not found, either install cuDNN, which requires registering an account and accepting their user license agreement here,, then copying files to the relevant locations, or re-comment the line USE_CUDNN=1 to # USE_CUDNN=1 in Makefile.config to disable it.


robertsdionne commented Jul 5, 2015

@porkroll, you probably have PYTHONPATH set to an incorrect value. Please re-run the following:

export PYTHONPATH="$HOME/caffe/distribute/python:$PYTHONPATH"

But replace $HOME/caffe/distribute/python with the correct path to where you downloaded the caffe git repository.

UTF-8 commented Jul 6, 2015

Trying to run the Notebook (which I don't understand)
ImportError Traceback (most recent call last)
in ()
7 from google.protobuf import text_format
----> 9 import caffe
11 def showarray(a, fmt='jpeg'):

ImportError: No module named caffe

pepyakin commented Jul 6, 2015

% pip install numpy scipy scikit-image pillow ipython[notebook]                                                                                                                 
zsh: no matches found: ipython[notebook]

solved by wrapping 'ipython[notebook]'

ludoplex commented Jul 7, 2015

When I use the command:
brew install --build-from-source --with-python --fresh -vd protobuf

My terminal keeps looping in circles spitting out the same warning:

clang: warning: optimization flag '-finline-functions' is not supported
clang: warning: argument unused during compilation: '-finline-functions'

any ideas what the issue might be?

aChase55 commented Jul 7, 2015

ludoplex - do a brew install normally, and then follow this quick guide, should straighten boost out for you.

ludoplex commented Jul 7, 2015

aChase55 - After running the command for a third time, it somehow managed to finish up. I'm not sure whether I should follow your advice or if the issue is resolved. I proceeded with the rest of the instructions (with the exception of editing the Makefile.conf and Makefile, which from the instructions I could not interpret whether I was to replace the originals with the commented out text provided in its entirety or not) but when it came to running "ipython notebook dream.ipynb" the page displayed an error message as follows: ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in ()
5 import PIL.Image
6 from IPython.display import clear_output, Image, display
----> 7 from google.protobuf import text_format
9 import caffe

ImportError: No module named google.protobuf

So what do you think I should do?

pgnyp commented Jul 7, 2015

my erorr messages: - but notepad runs...

can somebody tell me what next?

ljegou commented Jul 7, 2015

Hello, thanks for this script, which helped me to progress. However,it does'nt work on OSX 10.10.3 since homebrew opencv default is 2.4 and it lacks opencv_imgcodecs. I'm trying with opencv3.

Hey, just a comment for anyone having issues with cblas.h during caffe compilation, line BLAS_INCLUDE := /Applications/ may not exist, I had to change it to /System/Library/Frameworks/Accelerate.framework/Versions/Current/Frameworks/vecLib.framework/Versions/Current/Headers/ in OSX 10.10

tbcobra commented Jul 7, 2015

What am i missing to be able to configure the cp Makefile?

I have this message : make: *** [.build_release/cuda/src/caffe/layers/base_data_layer.o] Error 1

Do you know how I can fix it ?

Not sure if I'm doing right the "cp Makefile" part. I'm just doing a copy paste of the overall...

the errors appear when I do
make all -j6; make pycaffe -j6 (I have a 6 cores CPU)


I had similar problem. I managed to fix it by double checking the Makefile.config. I had mistakingly messed up so that I had two PYTHON_INCLUDE parameters active and the reference to numpy was faulty. I removed the second reference and made sure that the directory reference was in right format in the active one. As the python file refers to the numpy in it's include row like this: numpy/arrayobject.h, the reference in the PYTHON_INCLUDE parameter must point to directory under which there's directory numpy in which the actual arrayobject.h file resides. In my case the correct directory link was:


Hope this helps

If somebody else runs into problem:

error: [Errno 49] Can't assign requested address

In the last row call ipython notebook dream.ipynb, just try:

ipython notebook --ip= dream.ipynb

If somebody else is trying to use this: - I'm getting Segmentation fault: 11 when trying to do the second step. If somebody has resolved this I'd love to hear how.

Michikawa: could you give a printout of the entire error?
I'm really loving this moment of creativity and collaboration however, such a pleasure seeing so many people using AI for such creative endeavours!

Thank you for updating the git repo, now with the latest version everything is rolling! I only needed to change the file and changed the model_path reference to point absolutely to right folder and copied the .caffemodel file from here to same directory. Step 2 is now rolling :)

hey michikawa ! I also want to make deepdream video. Did you have same problem as mine ? I'm not very skilled in python and caffe... thanks !!

Sorry 12georgiadis, I didn't run into exactly that problem, so can't help right away :(

ludoplex commented Jul 7, 2015

graphific: Loved your Space Odyssey video. Any chance you could help me out with my setup?

same for me graphific... and nice video


robertsdionne commented Jul 8, 2015

@ludoplex I made the instructions clearer for the diff portions. Replace the red lines with the green lines.

Finally got it to compile (gpu, still waiting for nvidia to approve dev account). When I run the first imports in the notebook I get "The kernel appears to have died. It will restart automatically." Here's the crash report:
I tried running this first as you mentioned above

export PYTHONPATH="$HOME/caffe/distribute/python:$PYTHONPATH"

Then when I run the imports section of the notebook in the same terminal and execute the first cell I get this error in the notebook:

ImportError                               Traceback (most recent call last)
<ipython-input-2-8200bcb1df23> in <module>()
      7 from google.protobuf import text_format
----> 9 import caffe
     11 def showarray(a, fmt='jpeg'):

/Users/loremipsum/caffe/distribute/python/caffe/ in <module>()
----> 1 from .pycaffe import Net, SGDSolver
      2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver
      3 from .proto.caffe_pb2 import TRAIN, TEST
      4 from .classifier import Classifier
      5 from .detector import Detector

/Users/loremipsum/caffe/distribute/python/caffe/ in <module>()
     11 import numpy as np
---> 13 from ._caffe import Net, SGDSolver
     14 import

ImportError: dlopen(/Users/loremipsum/caffe/distribute/python/caffe/, 2): Library not loaded: @rpath/
  Referenced from: /Users/loremipsum/caffe/distribute/python/caffe/
  Reason: image not found

@12georgiadis I had the same problem. I had a previous version of boost installed, and the correct version wasn't linked. Follow these instructions:

ludoplex commented Jul 8, 2015

Thank you for the clarification. I will see if editing the file accordingly solves my problem.

When I try to enter
brew install --build-from-source --with-python --fresh -vd protobuf
I get 404 error "Downloading curl: (22) The requested URL returned error: 404 Not Found".
Am I the only one with this error? All I can see at this url is some strange xml

grimmzen commented Jul 8, 2015

For all those who get this error:
python/caffe/_caffe.cpp:10:10: fatal error: 'numpy/arrayobject.h' file not found

include <numpy/arrayobject.h>

Do this as root in the shell:
ln -s /usr/local/lib/python2.7/site-packages/numpy/core/include/numpy/ /usr/include/

This is great! Thanks for posting it on git!

The line:

import caffe

Causes a kernel crash with the following report:

Process: Python [64772]
Path: /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/Resources/
Identifier: Python
Version: 2.7.10 (2.7.10)
Code Type: X86-64 (Native)
Parent Process: Python [64589]
Responsible: iTerm [54669]
User ID: 501

Date/Time: 2015-07-08 13:35:09.084 -0300
OS Version: Mac OS X 10.10.4 (14E46)
Report Version: 11
Anonymous UUID: 6FA31699-055A-BCB5-F9E7-E994834275DE

Sleep/Wake UUID: B2B02058-057A-4673-B86F-F61110B06324

Time Awake Since Boot: 140000 seconds
Time Since Wake: 5400 seconds

Crashed Thread: 0 Dispatch queue:

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

Any ideas?

@UTF-8 Did you figure it out? I am getting the same error, and don't know notebook as well

elhongo commented Jul 8, 2015

When I run

# Build caffe
make all -j8; make pycaffe -j8

I get the following error. Does anyone know why? Is it because I have not properly installed google protocol buffer??

fatal error: 'google/protobuf/stubs/common.h' file not found
#include <google/protobuf/stubs/common.h>

mjkaufer commented Jul 8, 2015

I'm getting the following error

      7 from google.protobuf import text_format
----> 9 import caffe
     11 def showarray(a, fmt='jpeg'):

I can't import caffe from the normal Python REPL either. Same problem as @UTF-8 and @malonehedges

EDIT: It had to do with my PYTHONPATH not remaining set.

keevee09 commented Jul 8, 2015

after backdating boost and boost-python to 1.57 you might want to
brew pin boost and
brew pin boost-python
to prevent changes until there is a fix for boost.
Directly after
make all j4; make pycaffe -j4 (replace 4 with the number of eyes on your forehead)
it is good to test your install with
make runtest
This will compile the tests and then run them to see if everything is working.

diego- commented Jul 8, 2015

I am getting the same kernel crash as @AJCrowley.

ludoplex commented Jul 8, 2015

@robertsdionne I made the changes (with the exception of --- a/Makefile.config
+++ b/../caffe/Makefile.config in the Makefile.config and --- a/Makefile
+++ b/../caffe/Makefile in the Makefile because I could not find the code to be replaced), but I am still getting the error:

ImportError Traceback (most recent call last)
in ()
5 import PIL.Image
6 from IPython.display import clear_output, Image, display
----> 7 from google.protobuf import text_format
9 import caffe

ImportError: No module named google.protobuf

ludoplex commented Jul 9, 2015

I tried deleting and rewriting the import statement "from google.protobuf" and the error changed to the following:

ImportError Traceback (most recent call last)
in ()
6 from IPython.display import clear_output, Image, display
7 from google.protobuf import text_format
----> 8 import caffe
10 def showarray(a, fmt='jpeg'):

ImportError: No module named caffe

Is there a possibility to set it up without having a NVidia Graphics card GPU using unix?

when i try to do the make i get the following error

[jrivera@chamomile] $ make all -j8; make pycaffe -j8
/bin/sh: /usr/local/cuda/bin/nvcc: No such file or directory
(standard_in) 1: parse error
No receipt for '' found at '/'.
CXX src/caffe/blob.cpp
CXX src/caffe/common.cpp
CXX src/caffe/data_transformer.cpp
CXX src/caffe/internal_thread.cpp
CXX src/caffe/layer_factory.cpp
CXX src/caffe/layers/absval_layer.cpp
CXX src/caffe/layers/accuracy_layer.cpp
CXX src/caffe/layers/argmax_layer.cpp
In file included from src/caffe/common.cpp:5:
In file included from ./include/caffe/common.hpp:19:
./include/caffe/util/device_alternate.hpp:34:10: fatal error: 'cublas_v2.h' file not found
#include <cublas_v2.h>

did i miss a dependency somewhere? i thought maybe it was cuda, but i turned that off in the makefile since i didn't download that...

sgates commented Jul 9, 2015

For those getting the ImportError: No module named caffe, you either forgot to set the env variables:

export PYTHONPATH="$HOME/caffe/distribute/python:$PYTHONPATH"
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/lib:$HOME/caffe/distribute/lib:$DYLD_FALLBACK_LIBRARY_PATH


You did set them, but don't have $HOME set or don't actually have the caffe folder in your home. Replace $HOME with the path to where the caffe folder really is on your machine for both environment variable exports. In my case, I was just dumping stuff on my desktop, so my path was something like this:

export PYTHONPATH="/Users/<myUserName>/Desktop/caffe/distribute/python:$PYTHONPATH"

@robertsdionne thanks a bunch for the help on my previous question. Having another issue unfortunately.

linking warning saying that xcode can't find the Python library leading to the build failing because it cant find Python.h

make all -j8; make pycaffe -j8
CXX examples/siamese/convert_mnist_siamese_data.cpp
CXX .build_release/src/caffe/proto/
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/
clang: warning: argument unused during compilation: '-pthread'
ld: warning: directory not found for option '-L/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/'
CXX/LD -o .build_release/tools/caffe.bin
.... plus lots more ld warnings
PROTOC (python) src/caffe/proto/caffe.proto
python/caffe/_caffe.cpp:1:10: fatal error: 'Python.h' file not found

include <Python.h> // NOLINT(build/include_alpha)

The directory is there: $ ls /usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/
libpython2.7.dylib pkgconfig/ python2.7/

PYTHON_INCLUDE := /usr/local/lib/python2.7/site-packages/numpy/core/include/
PYTHON_LIB := /usr/local/lib/python2.7

Still having issues. When I use "make all -j8; make pycaffe -j8" I get the errors listed via the link. Can anyone please help?

When I run the notebook, or even just start the Python interpreter and type "import caffe" I get a segfault:

Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

VM Regions Near 0:
__TEXT 0000000102ac1000-0000000102ac3000 [ 8K] r-x/rwx SM=COW /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/Resources/

This is Python 2.7.9.
Any ideas?

diego- commented Jul 10, 2015

just a tip for those having problems, I was able to resolve my problems by updating XCode to the latest version, 6.4.

Make sure you update if you are running 6.3 or earlier!

was able to open the notebook, but when i try "run" on it, i appear to have the following error:

7 from google.protobuf import text_format
----> 9 import caffe
11 def showarray(a, fmt='jpeg'):
ImportError: No module named caffe

Could somebody help me, please?

Hi fellow #deepdream ers
Got pretty far in this, and ran into some sags at the end.
When I get to:
make all -j8; make pycaffe -j8
(in my case: make all -j4; make pycaffe -j4 because I have 4 core and not 8) I am getting error

./include/caffe/util/cudnn.hpp:5:10: fatal error: 'cudnn.h' file not found

include < cudnn.h >

and can't seem to get past it. Tried it on my other computer too, same thing.
Any suggestions?
I see some other people had a similar issue but I can't seem to find an answer? Did any of you find a resolution or work-around?
I have Xcode 6.4 btw

Hey @aidanfowler, were you able to figure out the python.h issue? I am seeing that problem.

snwman commented Jul 13, 2015

I am having the same problem with the python.h. among others. I noticed on my machine that frameworks is in folder 2.7.10_1
From what aidanfowler posted:
The directory is there: $ ls /usr/local/Cellar/python/2.7.10_1/Frameworks/Python.framework/Versions/2.7/lib/
libpython2.7.dylib pkgconfig/ python2.7/

check your file path for 2.7.10 or 2.7.10_1
Should the makefile have 2.7.10 replaced with 2.7.10_1 like as follows?
PYTHON_INCLUDE := /usr/local/lib/python2.7/site-packages/numpy/core/include/
PYTHON_LIB := /usr/local/lib/python2.7

cedac commented Jul 13, 2015

I'm getting this error:
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 7, in
from IPython import start_ipython
File "/usr/local/lib/python2.7/site-packages/IPython/", line 45, in
from .config.loader import Config
File "/usr/local/lib/python2.7/site-packages/IPython/config/", line 6, in
from .application import *
File "/usr/local/lib/python2.7/site-packages/IPython/config/", line 19, in
from IPython.config.configurable import SingletonConfigurable
File "/usr/local/lib/python2.7/site-packages/IPython/config/", line 12, in
from .loader import Config, LazyConfigValue
File "/usr/local/lib/python2.7/site-packages/IPython/config/", line 16, in
from IPython.utils.path import filefind, get_ipython_dir
File "/usr/local/lib/python2.7/site-packages/IPython/utils/", line 14, in
import tempfile
File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 32, in
import io as _io
File "/Users/cedac/caffe/python/caffe/", line 1, in
import numpy as np
File "/usr/local/lib/python2.7/site-packages/numpy/", line 170, in
from . import add_newdocs
File "/usr/local/lib/python2.7/site-packages/numpy/", line 13, in
from numpy.lib import add_newdoc
File "/usr/local/lib/python2.7/site-packages/numpy/lib/", line 8, in
from .type_check import *
File "/usr/local/lib/python2.7/site-packages/numpy/lib/", line 11, in
import numpy.core.numeric as _nx
File "/usr/local/lib/python2.7/site-packages/numpy/core/", line 46, in
from numpy.testing import Tester
File "/usr/local/lib/python2.7/site-packages/numpy/testing/", line 13, in
from .utils import *
File "/usr/local/lib/python2.7/site-packages/numpy/testing/", line 15, in
from tempfile import mkdtemp
ImportError: cannot import name mkdtemp

I think that the problem is that it is loading caffe instead of system's one, does anyone know how to solve this issue?

Thanks! This worked, with some tweaks. @snwman, my python was also installed to 2.7.10_1, so I made those changes to my Makefile.config. Had to clean but seemed ok afterwards. Also had to update my environment variables to point to the correct caffe dir.

One other note, I had to download the googlenet caffe models:
scripts/ models/bvlc_googlenet

gray808 commented Jul 14, 2015

Ok, after much headache, I got this set up and running. I've spent yesterday and today tinkering, and have been generating cool, creepy images.

But... I've been running this in Anaconda/Spyder. I somehow got a message in the IPython console that the connection to the kernel had crashed. I restarted Spyder, created a new IPython console, loaded the script (completely unchaged), and tried to run it. Now I am getting
ImportError: No module named caffe

It literally was just running, and had no problem finding the caffe module.
I thought maybe I'd corrupted the caffee install somehow, so reran 'make pycaffe', which told me
make: Nothing to be done for 'pycaffe'.

Any idea why it would suddenly lose it's memory of where to import caffe from, and how to make it remember?

i needed to install libpng1.6.17

==> Verifying boost-1.57.0.tar.bz2 checksum
Error: SHA1 mismatch
Expected: e151557ae47afd1b43dc3fac46f8b04a8fe51c12
Actual: ea60df615387f47bdfdfe4da48f6567c4ec60f74
Archive: /Library/Caches/Homebrew/boost-1.57.0.tar.bz2

I have edited /usr/local/Library/Formula/boost.rb to have the correct strings, but it still will not install, please help

class Boost < Formula
desc "Collection of portable C++ source libraries"
homepage ""
url ""
sha1 "e151557ae47afd1b43dc3fac46f8b04a8fe51c12"
head ""

bottle do
cellar :any
sha256 "9a3929bec0e9e9db36e005f57193433ac6b5ff9ff86b2ed3262b975d58488c19" => :yosemite
sha256 "c5ad1f8591ed91c551658fd198ce31cf9f6a8026fcbfd5970a39cb479e64faa2" => :mavericks
sha256 "7b154bf42d72bbb90c3017bb94b24fdd2e0605ceab8717283f5c9f456ac5c03d" => :mountain_lion

When i try running the make all j8; pycaffe j8 I get this error can someone please help.

I think it's better to use /usr/local/Frameworks/Python.framework/Versions/Current/include/python2.7 instead of /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/include/python2.7/ in PYTHON_INCLUDE and similarily /usr/local/Frameworks/Python.framework/Versions/Current/lib instead of /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/ in PYTHON_LIB.

At least this works for me in Mac OS 10.10.3.

Having the same issue as @Levixodus on make all -j8; make pycaffe -j8. Error is here:

XCode v.6.4, Mac OS 10.10.4. Also tried using cmake which amounted to the same errors.

@Levixodus: Check which version of boost is being used. It might be that you have 1.57.0 installed underneath 1.58.0. You would have to brew uninstall boost && brew link boost assuming 1.57.0 and 1.58.0 are both installed & managed by homebrew.

I've seen quite a few with the google.protobuf error and not really seeing any solutions here. Has anyone been able to address this error? I have everything 'working', or so it seems. When i run ipython in my terminal and import caffe, it seems to work. When I make runtest caffe it all comes back OK. I've followed all of the steps and the only thing I can think is that it's possible my ENV's aren't set correctly. But I'm immediately stopped in my tracks after the notebook launches and in the first module there is the dreaded "ImportError: No module named google.protobuf" error and I'm stopped right there. Or, at least it seems that way. Im in Ubuntu, but at this stage I'm not sure that matters as much. Help?

iaman commented Jul 22, 2015

brew install opencv didn't work for me (already had an opencv formula for whatever reason), brew install homebrew/science/opencv seems like the safer command

treyd commented Aug 11, 2015

I'm having the same issue as @Teepareep:

import caffe
Traceback (most recent call last):
File "", line 1, in
File "/Users/wilco/git/caffe/distribute/python/caffe/", line 1, in
from .pycaffe import Net, SGDSolver
File "/Users/wilco/git/caffe/distribute/python/caffe/", line 13, in
from ._caffe import Net, SGDSolver
ImportError: dlopen(/Users/wilco/git/caffe/distribute/python/caffe/, 2): Library not loaded: .so
Referenced from: /Users/wilco/git/caffe/distribute/python/caffe/
Reason: image not found

I didn't see any errors during compiling...

For the Python.h

I replaced

+PYTHON_INCLUDE := /usr/local/lib/python2.7/site-packages/numpy/core/include/ \

  •   /usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/include/python2.7/


+PYTHON_INCLUDE := /usr/local/lib/python2.7/site-packages/numpy/core/include/ \

  •  /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/include/python2.7/

(just 2.7.10_2 instead of 2.7.10) don't know why I have this confusing path...

I keep getting this error when trying to "Make" Caffe

"$ make all -j8; make pycaffe -j8
Makefile.config:3: *** missing separator. Stop.
Makefile.config:3: *** missing separator. Stop."

I followed the directions closely... and everything up to this point worked.

(edit) I took the Makefile and Makefile.config and reverted them to the "factory" settings, and the install of Caffe looks to be working. whether that will work with deepdream, i don't know..

gsabran commented Oct 13, 2015

Awesome work to make this installation simpler!
I've followed it carefully.
When running $ make runtest or import caffe I'm getting a similar error to @Teepareep:

ImportError: dlopen(/Users/guigou/caffe/distribute/python/caffe/, 2): Library not loaded: @rpath/
  Referenced from: /Users/guigou/caffe/distribute/python/caffe/
  Reason: image not found

any clue? Google seems to indicate to look at the DYLD_LIBRARY_PATH/DYLD_FALLBACK_LIBRARY_PATH but I could not change them successfully. DYLD_FALLBACK_LIBRARY_PATH is set as suggested in this post.

I'm running OSX 10.11 with anaconda and in the Makefile.config I've uncommented the lines

ANACONDA_HOME := $(HOME)/anaconda
    $(ANACONDA_HOME)/include/python2.7 \
    $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

and set


Don't know if that's relevant :)
Many thanks!

Thanks for this guide. I've followed the instructions and everything seemed to go smoothly. All the Caffe tests ran without issue. However when I try to do import caffe in python it crashes with:

Python 2.7.11 |Anaconda 2.5.0 (x86_64)| (default, Dec  6 2015, 18:57:58) 
[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: and
>>> import caffe
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6

I'm using CUDnn and I ran make with -j4 option since my MBP has 4 cores. I'm guessing something is breaking down on the python side. Any ideas of what I should check? Is there a way to get more information out of the crash?

Hey I was following the steps exactly as you told however at the point

diff --git a/Makefile.config b/../caffe/Makefile.config

its showing me an error that "unrecognized option diff --get". I would be really grateful if someone could help me out as to what I should be doing over here. Many thanks.

9Oeufs commented May 28, 2016 edited

After having almost all errors listed in this conversation, I had this issue I never seen and I don't know how to solve it, when I run the first cell of the ipython notebook


ImportError Traceback (most recent call last)
in ()
7 from google.protobuf import text_format
----> 9 import caffe
11 # If your GPU supports CUDA and Caffe was built with CUDA support,

/Users/MNv/caffe/distribute/python/caffe/ in ()
----> 1 from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver
2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver, layer_type_list
3 from ._caffe import version
4 from .proto.caffe_pb2 import TRAIN, TEST
5 from .classifier import Classifier

/Users/MNv/caffe/distribute/python/caffe/ in ()
13 from ._caffe import Net, SGDSolver, NesterovSolver, AdaGradSolver,
14 RMSPropSolver, AdaDeltaSolver, AdamSolver
---> 15 import
17 import six

/Users/MNv/caffe/distribute/python/caffe/ in ()
2 import
3 from scipy.ndimage import zoom
----> 4 from skimage.transform import resize
6 try:

/usr/local/lib/python2.7/site-packages/skimage/transform/ in ()
----> 1 from .hough_transform import (hough_line, hough_line_peaks,
2 probabilistic_hough_line, hough_circle,
3 hough_ellipse)
4 from .radon_transform import radon, iradon, iradon_sart
5 from .finite_radon_transform import frt2, ifrt2

/usr/local/lib/python2.7/site-packages/skimage/transform/ in ()
2 from scipy import ndimage as ndi
3 from .. import measure
----> 4 from ._hough_transform import (_hough_circle,
5 hough_ellipse as _hough_ellipse,
6 hough_line as _hough_line,

skimage/transform/_hough_transform.pyx in init skimage.transform._hough_transform (skimage/transform/_hough_transform.c:23691)()

/usr/local/lib/python2.7/site-packages/skimage/draw/ in ()
----> 1 from .draw import circle, ellipse, polygon_perimeter, set_color
2 from .draw3d import ellipsoid, ellipsoid_stats
3 from ._draw import (line, line_aa, polygon, ellipse_perimeter,
4 circle_perimeter, circle_perimeter_aa,
5 _bezier_segment, bezier_curve)

/usr/local/lib/python2.7/site-packages/skimage/draw/ in ()
4 from ._draw import _coords_inside_image
----> 6 from .._shared._geometry import polygon_clip
7 from ._draw import line

/usr/local/lib/python2.7/site-packages/skimage/_shared/ in ()
3 import numpy as np
----> 4 from matplotlib import _path, path, transforms

/usr/local/lib/python2.7/site-packages/matplotlib/ in ()
24 from numpy import ma
---> 26 from matplotlib import _path
27 from matplotlib.cbook import simple_linear_interpolation, maxdict
28 from matplotlib import rcParams

ImportError: cannot import name _path`

taiwotman commented Dec 16, 2016 edited

I got the following issue when I run the command on Mac OS Sierra:

python -c "import caffe" 

and here is the error message

python(38945,0x7fffaf2063c0) malloc: *** malloc_zone_unregister() failed for 0x7fffaf1fc000
Segmentation fault: 11

I will appreciate a kind suggestion.

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