2012-07-13 28 views
8

我試圖在我的Linux Mint 12上安裝scikit-learn,但失敗了。我從http://pypi.python.org/pypi/scikit-learn/下載的軟件包,並安裝了無法導入Scikit-Learn

sudo python2.7 setup.py install 

然後我改變了目錄,對家庭,開始python2.7外殼。在進口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 

回答

8

我真的不知道,但是當這取決於numpy的包被編譯針對特定版本(或一個特定的平臺)根據this恰巧錯誤,然後該程序包安裝在不同的環境。你是如何安裝這兩個軟件包的? (numpy和scipy)

我建議卸載並重新安裝SciPy,using pipfrom source

+0

謝謝mgibsonbr。我從源代碼重新安裝了scipy和numpy。之後'從scipy導入空間'沒有給出任何錯誤。但是,在導入sklearn時,我得到了一個不同的錯誤。我正在寫上面的錯誤。 – Rishi 2012-07-13 06:21:56

+1

我用'pip install -U scikit-learn'再次安裝了scikit-learn,之後導入工作。謝謝。 :) – Rishi 2012-07-13 06:42:27

+0

@Rishi那不適合我。我仍然得到'/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:91:RuntimeWarning:numpy.ufunc的大小改變,可能表明.qhull導入的二進制不兼容*' – 2014-08-25 13:31:07

1

我今天在OS X El Capitan遇到了這個問題。不幸的是,重新安裝/安裝不起作用,因爲問題最終導致OS X原生的numpy安裝優於pip安裝的安裝。

我能夠通過遵循指導來解決這個:https://apple.stackexchange.com/a/223163

特別是,我用固定蟒蛇路徑,通過OS X機庫喜歡點子庫的方法:

創建一個文件在/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