简体   繁体   English

无法在 spyder 上导入 sklearn

[英]Cannot import sklearn on spyder

I installed anaconda 3 full package, when I try to import sklearn module on spyder it give me the following error:我安装了 anaconda 3 完整包,当我尝试在 spyder 上导入 sklearn 模块时,它给了我以下错误:

import sklearn
Traceback (most recent call last):

  File "<ipython-input-1-8fd979e02004>", line 1, in <module>
    import sklearn

  File "C:\Users\username\Documents\Python Scripts\sklearn.py", line 11, in <module>
    from sklearn.naive_bayes import GaussianNB

ImportError: No module named 'sklearn.naive_bayes'; 'sklearn' is not a package

I am able to import sklearn on IPython, this must be a problem unique to Spyder, anyone got any idea why this is the case ?我可以在 IPython 上导入 sklearn,这一定是 Spyder 独有的问题,有人知道为什么会这样吗?

I ran into the same problem with my Ubuntu 16.04 installation.我的 Ubuntu 16.04 安装遇到了同样的问题。 I checked ipython console and ipython3 console and saw that sklearn loaded in ipython, the python 2 default, but not ipython3.我检查了 ipython 控制台和 ipython3 控制台,看到 sklearn 加载在 ipython 中,python 2 默认值,但不是 ipython3。

You will need to use pip3 to install scikit-learn.您将需要使用 pip3 来安装 scikit-learn。 Run the following: sudo apt-get update, then, sudo apt-get -y install python3-pip运行以下命令:sudo apt-get update,然后,sudo apt-get -y install python3-pip

After that run: sudo pip3 install scikit-learn运行之后: sudo pip3 install scikit-learn

I ran across the same problem recently and haven't been able to solve it that way.我最近遇到了同样的问题,但无法以这种方式解决。 Nevertheless, while running through an update problem I noticed the utilization of spyder through Anaconda solved all my problems.尽管如此,在解决更新问题时,我注意到通过 Anaconda 使用 spyder 解决了我所有的问题。

I uninstalled my basic spider and re-installed it through Ananconda where we're able to automatically manage spyder versions and avoid the libraries' problems.我卸载了我的基本蜘蛛并通过 Ananconda 重新安装它,在那里我们能够自动管理 spyder 版本并避免库的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM