caffe2
caffe2 copied to clipboard
Fatal Python error: PyThreadState_Get: no current thread on MacOS 10.12.5
Last few lines from verbose output:
python -v -c 'from caffe2.python import core'
.............
import caffe2.python.extension_loader # precompiled from caffe2/python/extension_loader.pyc
WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
WARNING:root:Debug message: No module named caffe2_pybind11_state_gpu
dlopen("caffe2/python/caffe2_pybind11_state.so", a);
Fatal Python error: PyThreadState_Get: no current thread
Abort trap: 6
My .bash_profile lines:
export PATH=$PATH:$HOME/bin:/usr/local/bin
export PYTHONPATH=/usr/local:$PYTHONPATH
export PYTHONPATH=$PYTHONPATH:$HOME/Work/Projects/caffe2/build
Python version:
python -c 'import sys; print(sys.version)'
2.7.13 (default, Jun 23 2017, 11:27:19)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)]
This is some lines from crash report:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fffa47c8d42 __pthread_kill + 10
1 libsystem_pthread.dylib 0x00007fffa48b6457 pthread_kill + 90
2 libsystem_c.dylib 0x00007fffa472e420 abort + 129
3 org.python.python 0x0000000110c7e88e Py_FatalError + 49
4 org.python.python 0x0000000110c7dd88 PyThreadState_Get + 28
5 org.python.python 0x0000000110c7ac82 Py_InitModule4_64 + 62
6 caffe2_pybind11_state.so 0x000000010ff6eb80 initcaffe2_pybind11_state + 48
7 org.python.python 0x000000010eb19fbe _PyImport_LoadDynamicModule + 150
8 org.python.python 0x000000010eb18ce3 import_submodule + 280
9 org.python.python 0x000000010eb1885d load_next + 273
10 org.python.python 0x000000010eb1783f PyImport_ImportModuleLevel + 656
11 org.python.python 0x000000010eafb000 builtin___import__ + 124
12 org.python.python 0x000000010ea854c1 PyObject_Call + 98
13 org.python.python 0x000000010eb07eb4 PyEval_CallObjectWithKeywords + 166
14 org.python.python 0x000000010eb03b9c PyEval_EvalFrameEx + 15400
15 org.python.python 0x000000010eaffd7f PyEval_EvalCodeEx + 1621
16 org.python.python 0x000000010eaff724 PyEval_EvalCode + 32
17 org.python.python 0x000000010eb16361 PyImport_ExecCodeModuleEx + 219
18 org.python.python 0x000000010eb19237 load_source_module + 1063
19 org.python.python 0x000000010eb18ce3 import_submodule + 280
20 org.python.python 0x000000010eb1885d load_next + 273
21 org.python.python 0x000000010eb1783f PyImport_ImportModuleLevel + 656
22 org.python.python 0x000000010eafb000 builtin___import__ + 124
23 org.python.python 0x000000010ea854c1 PyObject_Call + 98
24 org.python.python 0x000000010eb07eb4 PyEval_CallObjectWithKeywords + 166
25 org.python.python 0x000000010eb03b9c PyEval_EvalFrameEx + 15400
26 org.python.python 0x000000010eaffd7f PyEval_EvalCodeEx + 1621
27 org.python.python 0x000000010eaff724 PyEval_EvalCode + 32
28 org.python.python 0x000000010eb16361 PyImport_ExecCodeModuleEx + 219
29 org.python.python 0x000000010eb19237 load_source_module + 1063
30 org.python.python 0x000000010eb18ce3 import_submodule + 280
31 org.python.python 0x000000010eb18ade ensure_fromlist + 345
32 org.python.python 0x000000010eb178ea PyImport_ImportModuleLevel + 827
33 org.python.python 0x000000010eafb000 builtin___import__ + 124
34 org.python.python 0x000000010ea854c1 PyObject_Call + 98
35 org.python.python 0x000000010eb07eb4 PyEval_CallObjectWithKeywords + 166
36 org.python.python 0x000000010eb03b9c PyEval_EvalFrameEx + 15400
37 org.python.python 0x000000010eaffd7f PyEval_EvalCodeEx + 1621
38 org.python.python 0x000000010eaff724 PyEval_EvalCode + 32
39 org.python.python 0x000000010eb16361 PyImport_ExecCodeModuleEx + 219
40 org.python.python 0x000000010eb19237 load_source_module + 1063
41 org.python.python 0x000000010eb18ce3 import_submodule + 280
42 org.python.python 0x000000010eb18ade ensure_fromlist + 345
43 org.python.python 0x000000010eb178ea PyImport_ImportModuleLevel + 827
44 org.python.python 0x000000010eafb000 builtin___import__ + 124
45 org.python.python 0x000000010ea854c1 PyObject_Call + 98
46 org.python.python 0x000000010eb07eb4 PyEval_CallObjectWithKeywords + 166
47 org.python.python 0x000000010eb03b9c PyEval_EvalFrameEx + 15400
48 org.python.python 0x000000010eaffd7f PyEval_EvalCodeEx + 1621
49 org.python.python 0x000000010eaff724 PyEval_EvalCode + 32
50 org.python.python 0x000000010eb2157d run_mod + 49
51 org.python.python 0x000000010eb21743 PyRun_StringFlags + 100
52 org.python.python 0x000000010eb21699 PyRun_SimpleStringFlags + 69
53 org.python.python 0x000000010eb3263c Py_Main + 2188
54 libdyld.dylib 0x00007fffa469a235 start + 1
Compiled from sources without GPU support. Followed everything. Before i had python 2.6 and python 3 installed, i removed them. After that i rebuilt everything again. Still same error is produced. Thanks for advance.
This command is failing:
from caffe2.python.caffe2_pybind11_state import *
That error can be fixed if you tweak your python bindings.
Look here: https://caffe2.ai/docs/getting-started.html?platform=mac&configuration=compile#python-configuration
And you'll probably need to use the install_name_tool to point the library to the right python like this:
sudo install_name_tool -change libpython2.7.dylib ~/anaconda/lib/libpython2.7.dylib /usr/local/caffe2/python/caffe2_pybind11_state.so
Didnt help =(
sudo install_name_tool -change libpython2.7.dylib /usr/lib/libpython2.7.dylib /usr/local/caffe2/python/caffe2_pybind11_state.so
This is result of otool:
sudo otool -L /usr/local/caffe2/python/caffe2_pybind11_state.so
/usr/local/caffe2/python/caffe2_pybind11_state.so:
@rpath/libCaffe2_CPU.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/opt/protobuf/lib/libprotobuf.13.dylib (compatibility version 14.0.0, current version 14.0.0)
/usr/local/opt/glog/lib/libglog.0.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/opt/gflags/lib/libgflags.2.2.dylib (compatibility version 2.2.0, current version 2.2.0)
/usr/local/opt/opencv/lib/libopencv_highgui.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/local/opt/opencv/lib/libopencv_imgproc.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.10)
/usr/local/opt/opencv/lib/libopencv_core.2.4.dylib (compatibility version 2.4.0, current version 2.4.13)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
I also ran into this same error. I've tried setting my LD_LIBRARY_PATH, DYLD_LIBRARY_PATH, using install_name_tooland I'm still seeing
WARNING:root:This caffe2 python run does not have GPU support. Will run in CPU only mode.
WARNING:root:Debug message: No module named caffe2_pybind11_state_gpu
dlopen("caffe2/python/caffe2_pybind11_state.so", a);
Fatal Python error: PyThreadState_Get: no current thread
Hey I found the solution. I use pure python not anaconda or something else.
The cause of this problem is two versions existing in /usr/bin and /usr/local/bin
Luckily I got a whole new macbook. It only have one python 2.7.10 under /usr/bin and thus I didn't get this issue.
I have another macbook, which have two versions (2.7.13 under /usr/local/bin installed by brew)
The solution is to get rid of the 2.7.13 version. Then everything will be fine.
This is caused by linking a static version of libpython into ycmd's ycm_core.so. This leads to multiple copies of the python interpreter loaded when python loads ycmd_core.so and this messes up python's global state. The details aren't important.
The solution is that the version of Python linked and run against must be built with either --enable-shared or --enable-framework (on OS X). This is achieved as follows (NOTE: for Mac, replace --enable-shared with --enable-framework):
When building python from source: ./configure --enable-shared {options} When building python from pyenv: PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install {version}
Hi. I konw it's not directly related to your post however google index high this post, and i was going back and back here. If you deal with this problem with anaconda on windows What have helped me is upgrading python
activate myEnv
conda update python
This should have been fixed by https://github.com/pytorch/pytorch/commit/73f6715f4725a0723d8171d3131e09ac7abf0666 .
@ppwwyyxx thanks a lot for pointing out to proper fix! It saved me several hours or maybe few days.