Mac OS上的anaconda环境中的Swig抛出Fatal Python error: PyThreadState_Get: no current thread
我在Mac OS X上使用swig和conda寻找解决方案。
代码基于这个github示例,在Linux 16.04上运行良好,但在Mac OS X上运行失败
https://github.com/rdeits/swig-eigen-numpy
它在conda环境之外工作,但不在其内部。
这是我当前的环境conda list
asn1crypto 0.24.0 py36_0
bokeh 0.12.13 py36h2f9c1c0_0
bzip2 1.0.6 hd86a083_4
ca-certificates 2018.03.07 0
certifi 2018.4.16 py36_0
cffi 1.11.5 py36h342bebf_0
chardet 3.0.4 py36h96c241c_1
click 6.7 py36hec950be_0
cmake 3.9.4 h30c3106_0
cryptography 2.2.2 py36h1de35cc_0
curl 7.59.0 ha441bb4_0
cycler 0.10.0 py36hfc81398_0
expat 2.2.5 hb8e80ba_0
fastdtw 0.3.2 <pip>
flask 0.12.2 py36h5658096_0
freetype 2.8 h12048fb_1
gcloud 0.18.3 <pip>
gevent 1.2.2 py36ha70b9d6_0
googleapis-common-protos 1.5.3 <pip>
greenlet 0.4.13 py36h1de35cc_0
httplib2 0.11.3 <pip>
idna 2.6 py36h8628d0a_1
intel-openmp 2018.0.0 8
itsdangerous 0.24 py36h49fbb8d_1
jinja2 2.9.6 py36hde4beb4_1
libcurl 7.59.0 hf30b1f0_0
libcxx 4.0.1 h579ed51_0
libcxxabi 4.0.1 hebd6815_0
libedit 3.1 hb4e282d_0
libffi 3.2.1 h475c297_4
libgfortran 3.0.1 h93005f0_2
libpng 1.6.34 he12f830_0
libssh2 1.8.0 h322a93b_4
libuv 1.20.0 h1de35cc_0
livereload 2.5.1 <pip>
markupsafe 1.0 py36h3a1e703_1
matplotlib 2.0.2 py36h507e440_1
mkl 2018.0.2 1
ncurses 6.0 hd04f020_2
numpy 1.13.1 py36h93d791d_2
oauth2client 4.1.2 <pip>
openssl 1.0.2o h26aff7b_0
pandas 0.20.3 py36hd6655d8_2
patsy 0.5.0 py36_0
pcre 8.42 h378b8a2_0
pip 9.0.3 py36_0
protobuf 3.5.2.post1 <pip>
pyasn1 0.4.2 <pip>
pyasn1-modules 0.2.1 <pip>
pycparser 2.18 py36h724b2fc_1
pyopenssl 17.5.0 py36h51e4350_0
pyparsing 2.2.0 py36hb281f35_0
pysocks 1.6.8 py36_0
python 3.6.5 hc167b69_0
python-dateutil 2.6.1 py36h86d2abb_1
pytz 2017.2 py36h2e7dfbc_1
pyyaml 3.12 py36h2ba1e63_1
readline 7.0 hc1231fa_4
requests 2.18.4 py36h4516966_1
rhash 1.3.5 h3aa0507_1
rsa 3.4.2 <pip>
scipy 1.0.0 py36h1de22e9_0
setuptools 39.0.1 py36_0
six 1.11.0 py36h0e22d5e_1
sqlite 3.23.1 hf1716c9_0
statsmodels 0.8.0 py36h9c68fc9_0
swig 3.0.8 1
tk 8.6.7 h35a86e2_3
tornado 5.0.2 py36_0
urllib3 1.22 py36h68b9469_0
werkzeug 0.14.1 py36_0
wheel 0.31.0 py36_0
xz 5.2.3 h727817e_4
yaml 0.1.7 hc338f04_2
zlib 1.2.11 hf3cbc9b_2
答案 0 :(得分:1)
我在anaconda支持论坛上找到了答案的指针https://groups.google.com/a/continuum.io/forum/#!topic/anaconda/057P4uNWyCU
与anaconda一起提供的python 3.6二进制文件与python库静态链接。这就是为什么加载动态链接到它们的库会因重复符号而失败的原因。解决方案不是将库与python库链接。
神奇的部分(感觉就像一个解决方法)在SwigPython.cmake文件中
if(APPLE)
swig_link_libraries(${target} ${swigpy_LINK_LIBRARIES})
set_target_properties(${SWIG_MODULE_${target}_REAL_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
else()
swig_link_libraries(${target} ${swigpy_LINK_LIBRARIES} ${PYTHON_LIBRARIES})
endif()