今天在安装python 的 sklearn 包时出现了 Cannot uninstall 'numpy' 和 Cannot uninstall 'scipy'错误,下面记录了我尝试了很多网上的方法后最终成功的解决方法。

终端执行 pip install scikit-learn 后,出现 Cannot uninstall 'numpy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

执行 sudo pip install --upgrade --ignore-installed --install-option '--install-data=/usr/local' numpy 后成功更新 numpy,再次执行 pip install scikit-learn ,出现

Cannot uninstall 'scipy'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

执行 sudo pip install --upgrade scipy --ignore-installed six ,成功更新 scipy。

再次执行 pip install scikit-learn 后出现权限问题,运行 sudo pip install scikit-learn ,成功安装 sklearn包(见下图)。

另外,我在 Python 3 下安装 scikit-learn 没有出现该类错误,可能是因为 numpy 和 scipy 的版本够高。若是要在 python 3 下安装,前面的指令中 pip 用 pip3 替代。

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐