Error: Segmentation fault: 11
If you get the above error during import caffe in Python, check if the following path in [Caffe installation directory]/ makefile.config points to system Python instead of Homebrew version of Python.
PYTHON_INCLUDE and PYTHON_LIB
PYTHON_INCLUDE := /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/include/python2.7
PYTHON_LIB := /usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/
Then append Python directory in Caffe installation directory to PYTHONPATH as given below.
export PYTHONPATH=[Caffe installation directory]/python:$PYTHONPATH
Showing posts with label PyCaffe. Show all posts
Showing posts with label PyCaffe. Show all posts
Wednesday, July 27, 2016
Error: Fatal Python error: PyThreadState_Get: no current thread in Caffe (PyCaffe)
import caffe
Following error is encountered (and Python crashes) when executing the above import statement in Python. (PyCaffe)
Fatal Python error: PyThreadState_Get: no current thread
Usually, the error is due to the conflicts between different Python versions installed in the machine. If you tried the following step (re install), as mentioned in many other posts and still get the error, then try the trouble shooting steps that I have mentioned in this post. They worked for me :)
Caffe is primarily written in C++ and PyCaffe is it's Python interface. PyCaffe uses Boost Python
which is a C++ library to enable interoperability between C++ and the Python.
During the Caffe installation, we need to ensure that Boost Python is linked against Homebrew version of Python and not System Python. You can check the Python error report to check if there are any references to Python system libraries.
Use the following commands (in terminal) to check that.
otool -L [Caffe installation directory]/python/caffe/_caffe.so
otool -L /usr/local/opt/boost-python/lib/libboost_python.dylib
Note: You can replace the above libboost_python.dylib path with /usr/local/Cellar/boost-python/1.57.0/lib/libboost_python.dylib as well. (Additional info: Homebrew in /usr/local/Cellar/ - every formula is also linked to a /usr/local/opt directory. It provides a path for a formula's contents that does not change across version upgrades.)
otool is a command line tool that is being used to find dependencies of an executable. ‘-L’ option searches for the shared libraries used.
As a result of the above command, you may see a reference to Python system libraries as given below.
/System/Library/Frameworks/Python.framework/Versions/2.7/Python
Then you need to change the location to Homebrew version of Python using "install_name_tool" as given below.
install_name_tool [-change old new] input
E.g.,
sudo install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Frameworks/Python.framework/Versions/2.7/Python /usr/local/opt/boost-python/lib/libboost_python.dylib
After this, try import caffe, it should work as expected.
Following error is encountered (and Python crashes) when executing the above import statement in Python. (PyCaffe)
Fatal Python error: PyThreadState_Get: no current thread
Usually, the error is due to the conflicts between different Python versions installed in the machine. If you tried the following step (re install), as mentioned in many other posts and still get the error, then try the trouble shooting steps that I have mentioned in this post. They worked for me :)
brew uninstall boost-python
brew install --build-from-source --fresh -vd boost-pythonCaffe is primarily written in C++ and PyCaffe is it's Python interface. PyCaffe uses Boost Python
which is a C++ library to enable interoperability between C++ and the Python.
During the Caffe installation, we need to ensure that Boost Python is linked against Homebrew version of Python and not System Python. You can check the Python error report to check if there are any references to Python system libraries.
Use the following commands (in terminal) to check that.
otool -L [Caffe installation directory]/python/caffe/_caffe.so
otool -L /usr/local/opt/boost-python/lib/libboost_python.dylib
Note: You can replace the above libboost_python.dylib path with /usr/local/Cellar/boost-python/1.57.0/lib/libboost_python.dylib as well. (Additional info: Homebrew in /usr/local/Cellar/ - every formula is also linked to a /usr/local/opt directory. It provides a path for a formula's contents that does not change across version upgrades.)
otool is a command line tool that is being used to find dependencies of an executable. ‘-L’ option searches for the shared libraries used.
As a result of the above command, you may see a reference to Python system libraries as given below.
/System/Library/Frameworks/Python.framework/Versions/2.7/Python
Then you need to change the location to Homebrew version of Python using "install_name_tool" as given below.
install_name_tool [-change old new] input
E.g.,
sudo install_name_tool -change /System/Library/Frameworks/Python.framework/Versions/2.7/Python /usr/local/Frameworks/Python.framework/Versions/2.7/Python /usr/local/opt/boost-python/lib/libboost_python.dylib
After this, try import caffe, it should work as expected.
Subscribe to:
Posts (Atom)