Fatal Python error: PyThreadState_Get: no current thread

When I try and convert any Caffe model to mlmodel format I get the following error.


Fatal Python error: PyThreadState_Get: no current thread


I have tried in virtualenv with the following


virtualenv coreml_convert
cd coreml_convert
source bin/activate.fish
pip install -U coremltools

Then whn I try and convert the Caffe model in ipython it crashes python


In [2]: import coremltools

In [3]: coreml_model = coremltools.converters.caffe.convert('/Users/jameskellerman/Downloads/ResNet-152-model.caffemodel')
Fatal Python error: PyThreadState_Get: no current thread
fish: 'ipython' terminated by signal SIGABRT (Abort)


Output from otool -L

lib/python2.7/site-packages/coremltools/libcoremlpython.so:
  /usr/local/lib/libcoremlpython.dylib (compatibility version 1.0.0, current version 1.0.0)
  /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
  @rpath/libpython2.7.dylib (compatibility version 2.7.0, current version 2.7.10)
  /System/Library/Frameworks/CoreML.framework/Versions/A/CoreML (compatibility version 1.0.0, current version 1.0.0)
  /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1432.1.0)
  /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
  /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
  /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1432.0.0)


The file /usr/local/lib/libcoremlpython.dylib does not exist.


Any thoughts on this nasty problem?

Replies

I'm far from being an expert on this topic, but I had the same issue when I started testing out coremltools. I eventually found out that my version of Python didn't want to play well with coremltools, and I ended removing the Python I installed via brew (by doing brew uninstall python). On macOS 10.12, I took the same steps you seem to have done above, and it worked without issue. I gather this has something to do with coremltools being installed against the wrong Python path, but someone may be able to elaborate more (assuming you have the brew version of Python installed).

You need to set up your virtualenv like this:


virtualenv -p /usr/bin/python2.7 coreml_convert

Thanks for the help. I think you are right about coremltools being installed against the wrong path. I tried this without succes. I was using homebrew python, did the uninstall and then reinstall. Created new virtualenv and pip install coremltools. Hit the same problem.

This wordked so long as I used the python command line and not ipython. Thanks