Python: 安裝 sklearn 包出現錯誤的解決方法


今天在安裝 Python 的 sklearn 包時出現了 Cannot uninstall 'numpy' 和 Cannot uninstall 'scipy' 錯誤,下面記錄了我嘗試了很多網上的方法后最終成功的解決方法。

出現此類錯誤的主要原因應該是電腦上已安裝的 numpy 和 scipy 版本不夠高,pip 下載 sklean 時指令會自動刪除版本不夠的 numpy 和 scipy,刪除過程中出現無法刪除的錯誤,所以解決辦法就是要手動先升級 numpy 和 scipy。若是要在 python 3 下安裝,下面的所有指令中 pip 用 pip3 替代。

我的電腦是 Mac 系統,不確定 Linux 是否也是相同的解決指令,但思路應該是相同。

 

以下為具體操作:

終端執行 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 的版本夠高。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM