ImportError: dynamic module does not define module export function (PyInit__caffe)

Update
Caffe supports python 3.3+. Please checkout installation guide and prerequisites.

Original (outdated) answer
Using caffe with python 3 is not currently supported:

Caffe’s Python interface works with Python 2.7. Python 3 or earlier Pythons are your own adventure.

See caffe's installation tutorial.


It is now possible to build Caffe for Python3, and I'm almost sure it was possible in December 16 when the question was asked.

To do this, you need to remove the comments in the Makefile.config with Python3:

# Uncomment to use Python 3 (default is Python 2)
# Check that boost library name is correct here!!!
PYTHON_LIBRARIES := boost_python3 python3.5m
PYTHON_INCLUDE := /usr/include/python3.5m \
                 /usr/lib/python3.5/dist-packages/numpy/core/include

But therefore you will have caffe only in python3 OR python2, because of the way how caffe installs (with PYTHON_PATH, not a good way indeed).

To workaround this, you can do such trick in your ~/.bashrc:

alias python2="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py2/python && python2"
alias python3="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py3/python && python3"
alias python="export PYTHONPATH=$PYTHONPATH:/home/undead/reps/caffe_py2/python && python2"

Therefore both will works.