注意sklearn安装不是pip install sklearn
,而是pip install scikit-learn
;
使用清华源安装sklearn,windows中使用自己的python环境,在命令行输入如下:
pip install scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple
如果是在jupyter中安装:
可使用%pip
或者!pip
%pip install scikit-learn -i https://pypi.tuna.tsinghua.edu.cn/simple
导入scikit-learn
是用sklearn
,而不是安装时的名称scikit-learn
。
import sklearn
如果没有报错,则安装成功,如果报错如下:
No module named 'threadpoolctl'
则使用如下命令安装threadpoolctl
。
pip install -U threadpoolctl
由于No module named XXX
很常见,所以笔者想当然的使用pip install -U threadpoolctl
命令安装pip install threadpoolctl
,但好像无济于事。后面尝试加上参数-U
进行安装,发现能够成功导入sklearn
了。这或许和个人的电脑和配置的环境有关,特此记录一下。