基于Jupyter和Anacoda解决ImportError: cannot import name ‘CategoricalNB‘ from ‘sklearn.naive_bayes‘;cannot

解决历程

找了半天方法,最后发现sklearn的版本需要更新……

我使用的是Jupyter,所以在anacoda中更新版本了。顺便记录下怎么在anacoda中更新包吧。
在anacoda prompt 中输入命令conda update --all 将会更新所有包。
输入conda update package 或者 pip install --upgrade package 即更新某个包

但我输入上述的命令依旧不行……
最后想将sklearn包先卸载了,再重新导入的。基于Jupyter和Anacoda解决ImportError: cannot import name ‘CategoricalNB‘ from ‘sklearn.naive_bayes‘;cannot_第1张图片

命令 pip uninstall sklearn 卸载。
用清华镜像源 -i https://pypi.tuna.tsinghua.edu.cn/simple安装比较快。
然后, 依旧还是0.0版本,一口老血吐出来……

最终解决方法

又找了半天,发现这个命令 pip install --user --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple --ignore-installed scikit-learn 才是最终的解决办法

重启Jupyter查看版本:基于Jupyter和Anacoda解决ImportError: cannot import name ‘CategoricalNB‘ from ‘sklearn.naive_bayes‘;cannot_第2张图片
版本更新成功

你可能感兴趣的:(python,sklearn,开发语言)