Cannot import Scikit-Learn
Asked Answered
C

3

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
Consortium answered 13/7, 2012 at 5:7 Comment(0)
F
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.

Fasciculus answered 13/7, 2012 at 5:29 Comment(4)
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.Consortium
I installed scikit-learn again with pip install -U scikit-learn and after that the import worked. Thank you. :)Consortium
@Consortium 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 *Trever
This fix worked for me when using pip but not conda.Abundant
J
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

Jessalyn answered 16/8, 2016 at 6:35 Comment(0)
N
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

Nobleminded answered 3/2, 2014 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.