ImportError: No module named caffe

8,183 views
Skip to first unread message

Taran Dhillon

unread,
Jul 8, 2015, 9:53:14 AM7/8/15
to caffe...@googlegroups.com
Hi All. I have followed all the instructions, installed caffe and all dependencies correctly but i am receiving this error. Any help would be much appreciated.


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

ImportError: No module named caffe

Papa Roux

unread,
Jul 9, 2015, 11:47:35 PM7/9/15
to caffe...@googlegroups.com
I found your post while trying to install deepdream, because I was having the same problem.
I felt like a complete idiot when I figured out what I missed.

in editing my .bashrc, for PYTHONPATH, I missed the replacing of USERNAME with my actual username. Doh!

export PYTHONPATH="${PYTHONPATH}:/home/USERNAME/caffe/python"

Might not be your problem, but was mine. The next thing I hit was:
No module named skimage.io

Which is supposedly fixed with:
pip install -U scikit-image

...which is running at this time, and seems to take a while to complete. I'll keep you posted if you like.

Papa Roux

unread,
Jul 10, 2015, 12:05:01 AM7/10/15
to caffe...@googlegroups.com
OK all good now. I did actually need to sudo the pip install. Other than than, I am now dreaming! Good luck!

T

unread,
Jul 10, 2015, 12:32:14 AM7/10/15
to caffe...@googlegroups.com
Thanks for your response. All good now!
I've made a script that does the whole installation process for Debian if you would like a copy?

BadChimpStew

unread,
Jul 10, 2015, 6:27:05 AM7/10/15
to caffe...@googlegroups.com
I would love to check out your script!

T

unread,
Jul 10, 2015, 11:04:17 PM7/10/15
to caffe...@googlegroups.com
The script contains 3 files, as follows:
"dp.sh"
#!/bin/bash
sudo apt-get install ipython python-pil python-numpy python-scipy libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev python-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler libblas-common libblas-dev libblas-doc libblas-test libblas3 libblas3gf hdf5-helpers hdf5-tools libhdf5-8 libhdf5-8-dbg libhdf5-cpp-8 libhdf5-cpp-8-dbg libhdf5-dev libhdf5-doc libhdf5-mpi-dev libhdf5-mpich-8 libhdf5-mpich-8-dbg libhdf5-mpich-dev libhdf5-mpich2-dev libhdf5-openmpi-8 libhdf5-openmpi-8-dbg libhdf5-openmpi-dev libhdf5-serial-dev libhdf5-8 libhdf5-8-dbg libhdf5-dev libpdl-io-hdf5-perl libatlas-base-dev libatlas-dev libatlas-doc libatlas-test libatlas3-base libatlas3gf-base python-protobuf python-snappy libgflags-dev leveldb-doc snappy lmdb-utils lmdb-doc lmdb-dbg liblmdb0 liblmdb-dev nvidia-cuda-toolkit curl ipython-notebook Cython python-dateutil python-gflags python-numpy-dbg python-numpy-doc python-numpydoc python3-numpy python3-numpy-dbg python-scipy-dbg python-scipy-doc python-sciscipy python3-scipy python3-scipy-dbg python-matplotlib python-matplotlib-data python-matplotlib-dbg python-matplotlib-doc python-matplotlib-venn python3-matplotlib python3-matplotlib-dbg python3-matplotlib-venn python-h5py python-h5py-doc python3-h5py golang-goleveldb-dev libleveldb-api-java libleveldb-cil-dev libleveldb-dbg libleveldb-java libleveldb1 libleveldb1.2-cil python-leveldb python3-leveldb python-networkx python-networkx-doc python3-networkx python-django-nose python-nose python-nose-doc python-nose-parameterized python-nose-testconfig python-nose-timer python-nose-yanc python-nose2 python-nose2-cov python-nose2-doc python-nosehtmloutput python-nosexcover python-openstack.nose-plugin python-rednose python3-django-nose python3-nose python3-nose-parameterized python3-nose-timer python3-nose2 python3-nose2-cov python3-nosexcover python3-openstack.nose-plugin python3-rednose python-pandas python-pandas-doc python-pandas-lib python3-pandas python3-pandas-lib python-pil.imagetk python-sane python-pyocr python3-pyocr python-pil python-syck python-pip python-yaml

sudo apt-get install --no-install-recommends libboost-all-dev
sudo apt-get update
sudo apt-get upgrade

cd /usr/lib/x86_64-linux-gnu
sudo ln -s libhdf5_serial.so.8.0.2 libhdf5.so
sudo cp libhdf5.so libhdf5.so.10 
sudo ln -s libhdf5_serial_hl.so.8.0.2 libhdf5_hl.so
sudo cp libhdf5_hl.so libhdf5_hl.so.10 

# PROTOBUF
cd ~/Downloads
sudo rm master.zip
tar -zxvf protobuf-2.6.1.tar.gz
cd protobuf-2.6.1/
sudo ./configure
sudo make
sudo make check
sudo make install

# SCIKIT
sudo pip install -U scikit-image

# CAFFE
cd ~/Downloads
sudo rm master.zip
unzip master.zip
cp ~/Downloads/Makefile.config ~/Downloads/caffe-master
cd caffe-master/
sudo make all -j8
sudo make test
sudo make runtest
sudo make pycaffe
sudo make distribute

# DEEPDREAM
cd ~/Downloads
sudo rm master.zip
unzip master.zip
sudo rm master.zip

# FINAL UPDATES
sudo apt-get update
sudo apt-get upgrade



Makefile.config
# Contributions simplifying and improving our build system are welcome!

# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
# CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
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_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# 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 := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

BUILD_DIR := build
DISTRIBUTE_DIR := distribute

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1

# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0

# enable pretty build (comment to see full commands)
Q ?= @


README
1. Download and install Anaconda from https://store.continuum.io/cshop/anaconda/
2. Place Makefile.config and dp.sh in ~/Downloads type in "./dp.sh"
3. Run "export PYTHONPATH=/home/USERID/Downloads/caffe-master/python:$PYTHONPATH"
4. Run "sudo python /home/USERID/Downloads/caffe-master/scripts/download_model_binary.py /home/USERID/Downloads/caffe-master/models/bvlc_googlenet/"
5. Run "cd deepdream-master/"
6. Run "ipython notebook ./dream.ipynb"

7. Change the following:
"model_path = '../caffe/models/bvlc_googlenet/' # substitute your path here" TO model_path = '/home/USERID/Downloads/caffe-master/models/bvlc_googlenet/' # substitute your path here

yeshwanth Napolean

unread,
Jun 8, 2016, 5:39:02 AM6/8/16
to Caffe Users

Hello Everyone! I am new to caffe. I am trying to install it in ubuntu 14.04 which is running as a dual boot on my macbook pro. I managed to get it running initially but soon after my laptop crashed, following which I have the same error "No module named caffe" I have followed the instructions to the letter and it seems to be an issue with opencv. I get an error message while compiling caffe which I have copied below.

/usr/bin/ld: cannot find -lopencv_imgcodecs
collect2: error: ld returned 1 exit status
make: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

This leads me to believe there is something wrong with my OpenCV installation? Would really appreciate some help!

Chan Kim

unread,
Jun 8, 2016, 7:51:33 AM6/8/16
to Caffe Users
Did you try 'make pycaffe' in the caffe directory after making caffe? (This makes caffe exposed to python)

Jan

unread,
Jun 9, 2016, 5:05:39 AM6/9/16
to Caffe Users
I think opencv_imgcodecs is only present in OpenCV 3.x, not in OpenCV 2.x. I compiled current caffe just yesterday on Ubuntu 14.04 with OpenCV 3.1 using the cmake building method. I am not sure which version is required currently/whether you can set it in the Makefile.config

Jan
Reply all
Reply to author
Forward
0 new messages