问题
I successfully installed the pyopencl but I am getting an import error. I am stuck here and unable to progress further. Any help would be much appreciated
ImportError Traceback (most recent call last) in ()
5 from __future__ import division
6 import numpy as np
----> 7 import pyopencl
8 import pyopencl.array
9 import math, time
/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/init.py in () 32
33 try:
---> 34 import pyopencl.cffi_cl as _cl
35 except ImportError:
36 import os
/home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/cffi_cl.py in ()
37 from pytools import memoize_method
38
---> 39 from pyopencl._cffi import ffi as _ffi
40 from .compyte.array import f_contiguous_strides, c_contiguous_strides
41
ImportError: /home/highschool/anaconda2/lib/python2.7/site-packages/pyopencl-2016.2-py2.7-linux-x86_64.egg/pyopencl/_cffi.so: undefined symbol: _ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE
回答1:
The problem is the the dual ABI in libstdc++
with gcc5.1 for std::string
and std::list
. Anaconda now installs libstdc++.so.6.0.19
(presumably because they've added a Python package with a C++ library) from gcc 4.8.3 and pre dual ABI where as Ubuntu 16.04 comes with gcc 5.4 and libstdc++.6.0.21
. When you build pyopencl it builds and links against your system libstdc++
but when you try to import pyopencl
it dynamically links against the Anaconda one and fails to find the symbols.
It should be possible to solve this by adding -D_GLIBCXX_USE_CXX11_ABI=0
to the CXXFLAGS
list in the pyopencl siteconf.py
. That solves the std::string
issue but has other missing symbols:
ImportError: /home/cryan/anaconda3/lib/python3.6/site-packages/pyopencl-2016.2.1-py3.6-linux-x86_64.egg/pyopencl/_cffi.abi3.so: undefined symbol: _ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFvvE
Your options are:
- Install gcc from Anaconda (
conda install gcc
) and build pyopencl using that. Unfortunately if you have Anaconda on yourPATH
you'll use their gcc everywhere. - Just delete/rename the
libstdc++
in~/anaconda3/lib
:cd ~/anaconda3/lib; mv libstdc++.so libstdc++.annoying; mv libstdc++.so.6 libstdc++.annoying.6
. Python modules will find your system one which should be backwards compatible.
回答2:
I'm having the exact same issue.
ImportErrorTraceback (most recent call last)
<ipython-input-1-f1779268ba42> in <module>()
----> 1 import pyopencl as cl
/opt/anaconda2/lib/python2.7/site-packages/pyopencl/__init__.py in <module>()
32
33 try:
---> 34 import pyopencl.cffi_cl as _cl
35 except ImportError:
36 import os
/opt/anaconda2/lib/python2.7/site-packages/pyopencl/cffi_cl.py in <module>()
37 from pytools import memoize_method
38
---> 39 from pyopencl._cffi import ffi as _ffi
40 from .compyte.array import f_contiguous_strides, c_contiguous_strides
41
ImportError: /opt/anaconda2/lib/python2.7/site-packages/pyopencl/_cffi.so: undefined symbol: _ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE
I'm on Ubuntu 16.04, using the libOpenCL.so in AMDAPPSDK-3.0. I am able to run some of the OpenCL examples included with this SDK, so I believe this is a pyopencl issue.
来源:https://stackoverflow.com/questions/41096313/pyopencl-import-error-cffi-so-undefined-symbol