9

I tried to install scikit-learn on my Linux Mint 12 but failed. I downloaded the package from http://pypi.python.org/pypi/scikit-learn/ and installed with

sudo python2.7 setup.py install

I then changed the directory to home and started python2.7 shell. On importing sklearn I got:

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

I think the problem is with scipy's spatial. This is because when I do

>>> from scipy import spatial

I get the same error that I get for Scikit-learn.

Please help. Thank You.

EDIT: New error.

>>> 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
Rishi
  • 1,987
  • 6
  • 32
  • 49

3 Answers3

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.

Community
  • 1
  • 1
mgibsonbr
  • 21,755
  • 7
  • 70
  • 112
  • Thank You mgibsonbr. I re-installed scipy and numpy from source. After that `from scipy import spatial` gave no error. But, on importing sklearn I get a different error. I am writing the error above. – Rishi Jul 13 '12 at 06:21
  • 2
    I installed scikit-learn again with `pip install -U scikit-learn` and after that the import worked. Thank you. :) – Rishi Jul 13 '12 at 06:42
  • @Rishi That did not work for me. I still get `/usr/local/lib/python2.7/dist-packages/scipy/spatial/__init__.py:91: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility from .qhull import *` – Martin Thoma Aug 25 '14 at 13:31
  • This fix worked for me when using `pip` but not `conda`. – Bret Cameron Jul 22 '19 at 10:53
1

I ran into this today on OS X El Capitan. Unfortunately, reinstalling/installing didn't work, since the problem ended up being that numpy installation native to OS X was preferred over the one being installed by pip.

I was able to solve this by following the guidance in: https://apple.stackexchange.com/a/223163

In particular, I used the approach of fixing the python path to prefer pip libraries over OS X native libraries:

Create a file called fix_mac_path.pth in /Library/Python/2.7/site-packages that has the following:

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

Community
  • 1
  • 1
0

i was having the exact same problem. I managed to make it work by installing the windows binary for 64 bit windows from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn . Hope this works for you