无法下载和安装 scikit-learn

Cannot download and install scikit-learn

我是 python 的新手。我想使用 KMean 代码,我想安装 scikit-learnsklearn

我使用此代码尝试安装这些软件包:

pip install -U sklearn
pip install -U scikit-learn

但是我得到了这个错误:

Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_reihaneh/sklearn/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-89YQB7-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_reihaneh/sklearn
Storing debug log for failure in /home/reihaneh/.pip/pip.log

问题的原因是什么?

pip install -U <package>pip install --upgrade <package> 的缩写,将 <package> 升级到 pip repo 中的最新稳定版本。

pip install <package> 将在 pip 仓库中安装 <package> 的最新稳定版本。

区别在于升级与安装。你想要后者。

scikit-learn 需要 scipynumpy,所以这里是您应该发出的命令:

pip install numpy
pip install scipy
pip install scikit-learn

如果您已经有任何依赖项,只需在 pip install 和包名称之间插入一个 -U

如果您使用的是 Python 3.x,请将 pip 替换为 pip3