9

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

sudo python2.7 setup.py install

然后我将目录更改为 home 并启动 python2.7 shell。在导入 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-learn 相同的错误。

请帮忙。谢谢你。

编辑:新错误。

>>> 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
4

3 回答 3

11

I'm not really sure, but according to this that error happens when a package that depends on numpy is compiled targeting a specific version (or a specific platform), and that package is then installed in a different environment. How did you install those two packages? (numpy and scipy)

I'd suggest uninstalling both and then reinstalling SciPy, either using pip or from source.

于 2012-07-13T05:29:16.327 回答
1

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

我能够按照以下指南解决此问题:https ://apple.stackexchange.com/a/223163

特别是,我使用修复 python 路径的方法来更喜欢 pip 库而不是 OS X 本地库:

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

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

于 2016-08-16T06:35:09.767 回答
0

我遇到了完全相同的问题。我设法通过从http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn安装 64 位 Windows 的 Windows 二进制文件来使其工作。希望这对你有用

于 2014-02-03T23:41:38.630 回答