importing module in Spyder error

2019-05-10 09:13发布

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

2条回答
2楼-- · 2019-05-10 09:43

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

查看更多
Summer. ? 凉城
3楼-- · 2019-05-10 09:44

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

查看更多
登录 后发表回答