3

I am trying to use sklearn in Spyder. At the beginning when I tried to import it I was gettingImportError: No module named sklearn

Then I tied to set the PATH with PYTHONPATH manager and then use 'Update module names list' from tools menu.then restart the spydet but no success.

at the end I copied the sklearn folder to /Applications/Spyder.app/Contents/Resources/lib/python2.7

This is how I find the PATH of sklearn and copied in into this folder :

>>> import sklearn
>>> sklearn
<module 'sklearn' from '/Library/Python/2.7/site-packages/scikit_learn-0.12_git-py2.7-macosx-10.7-intel.egg/sklearn/__init__.pyc'>
>>> 

and then I cd to the parent folder :

cp -r sklearn /Applications/Spyder.app/Contents/Resources/lib/python2.7

but when I try to import the sklearn to spyder like from sklearn import dataset :

Traceback (most recent call last):
  File "/Users/mohsenjadidi/Documents/workspace/dsv/test.py", line 10, in <module>
    from sklearn import dataset
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/__init__.py", line 17, in <module>
    from .base import clone
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/base.py", line 11, in <module>
    from .metrics import r2_score
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/__init__.py", line 6, in <module>
    from .metrics import confusion_matrix, roc_curve, auc, precision_score, \
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/metrics/metrics.py", line 17, in <module>
    from ..utils import check_arrays
  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/sklearn/utils/__init__.py", line 9, in <module>
    from .murmurhash import murmurhash3_32
  File "numpy.pxd", line 151, in init sklearn.utils.murmurhash (sklearn/utils/murmurhash.c:4773)
ValueError: numpy.dtype has the wrong size, try recompiling

any idea?Thanks

Moj
  • 6,137
  • 2
  • 24
  • 36

2 Answers2

3

Moj, Spyder MacOS X App uses its own (internal) Python interpreter, not the system one. This was the only way we (the devs) found to provide a self contained app with numpy, scipy, matplotlib and IPython, without messing with system Python.

Right now I think there is no way to add more packages to the app, but we'll try to improve the situation during the next couple of months.

The other alternative (the one we envisaged) is for users who want more packages to download and install latest EPD and change their Python interpreter in

Tools > Preferences > Console > Advanced Settings > Python Executable

Community
  • 1
  • 1
Carlos Cordoba
  • 33,273
  • 10
  • 95
  • 124
0

I faced the same problem importing networkx. Drag-drop its folder into spyder's folder was enough for me.

Gabriele Pompa
  • 361
  • 4
  • 12
  • I'm glad that that worked for you, but this is not the recommended way to do it, because it's prone to failure () – Carlos Cordoba Jun 28 '13 at 21:37
  • Thanks! I've changed the interpreter and it works fine also now: found inside the App all the libraries I previously got! But, just for curiosity, apart from the waste of memory, why the drag-drop should be avoided? Thanks in advance – Gabriele Pompa Jun 29 '13 at 17:14
  • Because the dirs you move can contain compiled libraries (i.e. dylib files) and those only work on the python interpreter they belong to. – Carlos Cordoba Jun 29 '13 at 22:09