2

For DeepDream or other deeplearning project, constructing environment of Caffe.

I installed required packages for PyCaffe and made PYTHONPATH to caffe/python.

However when I import caffe on python:

import caffe

Error occurred as below.How to solve this problem?

Segmentation fault: 11
koppepanna
  • 139
  • 2
  • 6
  • Possible duplicate of http://stackoverflow.com/questions/28669587/python-segmentation-fault-11-when-running-import-cv-or-import-cv2. – Forge Feb 17 '16 at 15:55
  • Thanks for your recommendation. However this time I stuck on Caffe, not openCV, and I use Python 2.7.10. I think my question is different from you mentioned. – koppepanna Feb 17 '16 at 16:03
  • Did you try the solutions suggested on that link? – Forge Feb 17 '16 at 16:04
  • Yes, I tried "sudo python" and "import caffe" as that link suggested, but then I got error "ImportError: No module named caffe". – koppepanna Feb 17 '16 at 16:10

3 Answers3

1

Are you using a mac? I had a very hard time making pycaffe on mac, until I realized that there is a native python installed on all macs and that I was using another version I had installed. While compiling, caffe was using some of the stuff from the native python, and some of the stuff from the other python. I had to make sure to change all the relevant paths in the makefile.config file and to change the python my bash was using. I recommend working in a virtual environment as well. This is a good link to help you out, good luck!

jerpint
  • 399
  • 2
  • 16
1

This has been discussed since 2015 in Github issue. Mostly the reason is the conflict of homebrew python and OS X system python.

Homebrew has provided an awesome solution for OS X:

$ python -V   # system Python interpreter
$ python2 -V  # Homebrew installed Python 2 interpreter
$ python3 -V  # Homebrew installed Python 3 interpreter (if installed)

So the solution is changing all the python paths to python2. Bellowing is my Makefile.config related:

# ...
# 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
# ------ For Homebrew installed python. Numpy path is added using python commands. 
PYTHON_INCLUDE := /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/include/python2.7

# We need to be able to find libpythonX.X.so or .dylib. ------ (Update Homebrew path)
# PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib
PYTHON_LIB := /usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib

# Homebrew installs numpy in a non standard path (keg only) ------ (python2 for brew instead of python for system)
PYTHON_INCLUDE += $(dir $(shell python2 -c 'import numpy.core; print(numpy.core.__file__)'))/include
PYTHON_LIB += $(shell brew --prefix numpy)/lib
# ...
thundertrick
  • 1,634
  • 1
  • 17
  • 22
0

Try to manually set python path in your python script if you get no module named caffe error

Ex. import sys

sys.path.insert(0, "/home/nviso/GitHub/caffe/distribute/python")

import caffe

This generally works for me. Adding the caffe or python path to .bashrc manually should probably solve the issue as well though not sure, don't have my Office PC now to try :)