Solvedcaffe malloc error on macOS Sierra 10.12

I was able to compile and run an example (mnist), but when the example starts I see the following:

caffe(51829,0x7fffc23a93c0) malloc: *** malloc_zone_unregister() failed for 0x7fffc239f000

The example proceeds to run, but when I open up the python interpreter and import caffe, I see a similar error and the interepreter crashes:
import caffe
Python(14990,0x7fffc23a93c0) malloc: *** malloc_zone_unregister() failed for 0x7fffc239f000 /usr/local/lib/python2.7/site-packages/matplotlib/ UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment. warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
[1] 14990 illegal hardware instruction python

Not sure what causes this?

30 Answers

✔️Accepted Answer

the problem is related to leveldb. If leveldb is installed with brew, by default, it depends on the google's gperftools, which consists of a module named libtcmalloc.dylib. On macOS sierra, this causes the malloc_zone_unregister problem.

therefore, there are two solutions:

  1. comment out the line USE_LEVELDB := 0 in Makefile.config
  2. download the leveldb(v1.9) and compile it to replace the original one.

Other Answers:

I got it to work! I still get a malloc error but python doesn't crash and Caffe's now working.
How it goes:
screen shot 2016-10-14 at 12 04 14 pm

Here's what I did:
Step 1: Check your 'Makefile.config' file. You basically want to see if the following two entries are according to your paths:
PYTHON_LIB := /usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/
Correct these if there're any discrepancies.

Step 2: Go to your CAFFE_ROOT/Python folder. Run python from this directory using the terminal. Import pyplot using the command: import matplotlib.pyplot
This should take some time. Be patient. Once this is done, quit the Python shell. Run the shell again. Import Caffe and it should hopefully work!

Uncomment USE_LEVELDB := 0. There is an incompatibility with macOS Sierra and LevelDB and you want to disable it.

Using the HEAD version of gperftools can also fix the problem.
brew reinstall gperftools --HEAD

More Issues: