无法导入Scikit Learn



我试图在Linux Mint 12上安装scikit learn,但失败了。我从下载了软件包http://pypi.python.org/pypi/scikit-learn/并安装

sudo python2.7 setup.py install

然后,我将目录更改为home,并启动python2.7shell。关于进口sklearn我得到:

>>> import sklearn
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning: 
numpy.dtype size changed, may indicate binary incompatibility
    from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning:
numpy.ndarray size changed, may indicate binary incompatibility
    from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:7: RuntimeWarning: 
numpy.ufunc size changed, may indicate binary incompatibility
    from ckdtree import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning: 
numpy.dtype size changed, may indicate binary incompatibility
    from qhull import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning: 
numpy.ndarray size changed, may indicate binary incompatibility
    from qhull import *
/usr/lib/python2.7/dist-packages/scipy/spatial/__init__.py:8: RuntimeWarning:  
numpy.ufunc size changed, may indicate binary incompatibility
    from qhull import *

我认为问题出在scipy的空间上。这是因为当我做时

>>> from scipy import spatial

我得到了与Scikit学习相同的错误。

请帮忙。非常感谢。

编辑:新错误。

>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/__init__.py", line 17, in <module>
    from .base import clone
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/base.py", line 11, in <module>
    from .metrics import r2_score
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/metrics/__init__.py", line 6, in <module>
    from .metrics import confusion_matrix, roc_curve, auc, precision_score, 
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-  
x86_64.egg/sklearn/metrics/metrics.py", line 17, in <module>
    from ..utils import check_arrays
  File "/usr/local/lib/python2.7/dist-packages/scikit_learn-0.12_git-py2.7-linux-
x86_64.egg/sklearn/utils/__init__.py", line 9, in <module>
    from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 174, in init sklearn.utils.murmurhash (sklearn/utils
/murmurhash.c:4776)
ValueError: numpy.ndarray has the wrong size, try recompiling

我真的不确定,但根据这一点,当一个依赖于numpy的包被编译为针对特定版本(或特定平台),然后该包被安装在不同的环境中时,就会发生错误。你是如何安装这两个软件包的?(numpy和scipy)

我建议卸载两者,然后重新安装SciPy,使用pip或从源代码。

我今天在OS X El Capitan上遇到了这个问题。不幸的是,重新安装/安装不起作用,因为问题最终是OS X原生的numpy安装比pip安装的更受欢迎。

我能够按照中的指导解决此问题:https://apple.stackexchange.com/a/223163

特别是,我使用了修复python路径的方法,更喜欢pip库而不是OSX原生库:

/Library/Python/2.7/site-packages中创建一个名为fix_mac_path.pth的文件,该文件包含以下内容:

import sys; std_paths=[p for p in sys.path if p.startswith('/System/')]; sys.path=[p for p in sys.path if not p.startswith('/System/')]+std_paths

我遇到了完全相同的问题。我通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit学习。希望这对你有效

相关内容

  • 没有找到相关文章

最新更新