升级到sklearn 0.15后导入错误

时间:2014-08-03 11:10:55

标签: python ubuntu numpy scipy scikit-learn

使用Ubuntu 13.10 64位和python 2.7.5。我已经使用了sklearn 0.14很长一段时间了。通过以下方式升级到版本0.15后

pip install --upgrade scikit-learn

我遇到了以下情况:

from sklearn import svm

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
  File "sklearn/svm/classes.py", line 1, in <module>
    from .base import BaseLibLinear, BaseSVC, BaseLibSVM
  File "sklearn/svm/base.py", line 9, in <module>
    from . import libsvm_sparse
  File "libsvm_sparse.pyx", line 5, in init sklearn.svm.libsvm_sparse (sklearn/svm/libsvm_sparse.c:6773)
  File "sklearn/utils/__init__.py", line 11, in <module>
    from .validation import (as_float_array, check_arrays, safe_asarray,
  File "sklearn/utils/validation.py", line 17, in <module>
    from .fixes import safe_copy
  File "sklearn/utils/fixes.py", line 18, in <module>
    from .testing import ignore_warnings
  File "sklearn/utils/testing.py", line 36, in <module>
    from nose.tools import assert_equal
ImportError: No module named nose.tools

然后,如果我再试一次 -

from sklearn import svm

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sklearn/svm/__init__.py", line 13, in <module>
    from .classes import SVC, NuSVC, SVR, NuSVR, OneClassSVM, LinearSVC
  File "sklearn/svm/classes.py", line 1, in <module>
    from .base import BaseLibLinear, BaseSVC, BaseLibSVM
  File "sklearn/svm/base.py", line 8, in <module>
    from . import libsvm, liblinear
ImportError: cannot import name libsvm

导入sklearn本身不会引发ImportErrors。

类似问题的其他答案建议卸载和重新安装,这有助于其他人,但不是我的情况。

编辑: 卸载并重新安装几次后,包括卸载和重新安装scikit-image,问题似乎已经过去了,或者至少有所改变。 我现在得到以下内容:

from sklearn import svm
/usr/local/lib/python2.7/dist-packages/scipy/stats/_continuous_distns.py:24: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from . import vonmises_cython
/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py:188: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from ._rank import rankdata, tiecorrect
/usr/local/lib/python2.7/dist-packages/scipy/interpolate/interpolate.py:28: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from . import _ppoly
/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:90: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .ckdtree import *
/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:91: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility
  from .qhull import *

(我正在使用numpy 1.8.1)

然而,除了警告之外,事情看起来像是在起作用。 我不知道导致问题的原因,或者修改了什么。也许先安装sklearn,然后再滑雪...

编辑2: 通过完全删除scipy和numpy解决了问题(包括从/usr/local/lib/python2.7/dist-packages/和/ usr / share / pyshared /)手动删除它们。

1 个答案:

答案 0 :(得分:1)

安装scikitlearn时,依赖包似乎有问题(虽然它之前也没有发生过)。我通过运行

安装了鼻子
pip install nose

并且错误消失了。希望这会有所帮助。