undefined symbol: clapack_sgesv

2020-04-10 03:13发布

问题:

I have this little code:

from numpy import *
from scipy import signal, misc
import matplotlib.pyplot as plt

path="~/pics/"
band_1 = misc.imread(path + "foo.tif");

H = array((1/2.0, 1/4.0, 1/2.0));
signal.convolve2d(band_1.flatten(), H)

plt.figure()
plt.imshow(band_1)
plt.show()

then I execute this code python foo.py and it throws this error:

Traceback (most recent call last):
  File "foo.py", line 2, in <module>
    from scipy import signal
  File "/usr/lib/python2.6/site-packages/scipy/signal/__init__.py", line 10, in <module>
    from filter_design import *
  File "/usr/lib/python2.6/site-packages/scipy/signal/filter_design.py", line 12, in <module>
    from scipy import special, optimize
  File "/usr/lib/python2.6/site-packages/scipy/optimize/__init__.py", line 14, in <module>
    from nonlin import *
  File "/usr/lib/python2.6/site-packages/scipy/optimize/nonlin.py", line 113, in <module>
    from scipy.linalg import norm, solve, inv, qr, svd, lstsq, LinAlgError
  File "/usr/lib/python2.6/site-packages/scipy/linalg/__init__.py", line 9, in <module>
    from basic import *
  File "/usr/lib/python2.6/site-packages/scipy/linalg/basic.py", line 14, in <module>
    from lapack import get_lapack_funcs
  File "/usr/lib/python2.6/site-packages/scipy/linalg/lapack.py", line 15, in <module>
    from scipy.linalg import clapack
ImportError: /usr/lib/python2.6/site-packages/scipy/linalg/clapack.so: undefined symbol: clapack_sgesv

What is wrong? It seems to be from scipy import signal but I do not know clearly.

I have check another sources and forums but there is no reasons yet:

  • http://old.nabble.com/scipy.interpolate-imports---%3E-lapack-errors-td30343730.html
  • http://permalink.gmane.org/gmane.comp.python.scientific.user/27290

Thank you

回答1:

On Debian, you can use update-alternatives, assuming you have more than reference implementation installed.

From debian wiki

update-alternatives --config liblapack.so.3
update-alternatives --config libblas.so.3


回答2:

I can't be certain since you didn't specify what distribution you're using, but I ran into the same issue on Gentoo.

/usr/lib and /usr/lib64 have symlinks to the actual libraries. By default, it links to the reference implementation of libblas, libcblas, and liblapack -- which doesn't export symbols for clapack_sgesv, and many other routines.

To resolve this in Gentoo:

sudo emerge blas-atlas
eselect blas list
eselect cblas list
sudo eselect blas set X # Grab X from the result of
sudo eselect cblas set X # the 'list' lines above
sudo emerge lapack-atlas
eselect lapack list
sudo eselect lapack set X
sudo emerge --unmerge scipy numpy matplotlib
sudo emerge scipy numpy matplotlib (... whatever else ...)


回答3:

I got this problem after an upgrade from Ubuntu 12.04 to 12.10. The problem was that I had two versions of scipy installed in /usr/local/lib/python2.7/dist-packages. To fix the problem I did:

 sudo apt-get remove python-scipy
 sudo rm -fr /usr/local/lib/python2.7/dist-packages/scipy*
 sudo apt-get install python-scipy