- 異常1:PackagesNotFoundError: The following packages are not available from current channels:
- 異常2: RuntimeError: Cython extensions are unavailable. Without them, this gensim functionality is disabled.
- 總結
異常1:PackagesNotFoundError: The following packages are not available from current channels:
conda install X
出現找不到X包問題,如下所示:默認的channels里找不到。
解決方案1:用pip install X
來安裝X包,發現可以找到包並下載,然后等待能否successfully。
如果出現一直等待的Installing build dependencies ...
這里應該是缺少Python 依賴,可以嘗試添加新鏡像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
之后再試一下能否正常安裝X包:Python是否可以import。
如果出現pip的warning:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
因為pip安裝第三方庫需要ssl模塊,而python默認安裝ssl功能是不可用的.
解決方法1-1:針對pip is configured with locations that require TLS/SSL問題:重新編譯Python3安裝文件,加上--with-ssl參數讓pip3使用SSL功能。
# 重新編譯安裝
./configure --enable-optimizations --with-ssl
注意:可以參考:異常處理pip is configured with locations that require TLS/SSL
解決方法1-2:針對pip is configured with locations that require TLS/SSL問題:更換pip源,即添加國內鏡像。
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
國內一些常用的軟件源如下:
阿里雲:http://mirrors.aliyun.com/pypi/simple/
中國科技大學:https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣:http://pypi.douban.com/simple/
清華大學:https://pypi.tuna.tsinghua.edu.cn/simple/
中國科學技術大學:http://pypi.mirrors.ustc.edu.cn/simple/
注意:添加這個國內鏡像,可能會與你已經存在的來自conda-forge的包產生沖突,因為版本不統一,就造成import一個包(來自國內鏡像)時,因為需要另幾個包(可能來自conda-forge和Anaconda默認鏡像)的支持,而引發導入錯誤,所以還是統一下。
個人還是推崇用default的,雖然下載比較慢,但是版本更新及時且很少有沖突。因為吃過清華源的虧。
如果嫌麻煩,安裝了Anaconda的請看解決方案2.
解決方案2:不要終端命令了,直接使用Anaconda Navigator界面Environments里手動添加吧。
如果安裝成功,檢查下Python里能否import了,如果import不成功,又出幺蛾子了,那就繼續修行。可以看異常2了。
異常2: RuntimeError: Cython extensions are unavailable. Without them, this gensim functionality is disabled.
這個是我在安裝gensim時出錯,這個之前在Windows上就經常安裝報錯,這次在macOS M1芯片上依舊坑了。
利用miniforge3創建的conda環境(base) [/Users/dan/miniforge3/bin/python]是可以通過pip install gensim安裝成功且可以import的。如下所示。
但是在自己創建的虛擬環境(py38)[/Users/dan/miniforge3/envs/py38/bin/python]下就報錯了。
Anaconda上顯示安裝成功,但是import時就不行了。
然后卸了,重新pip install gensim 裝下。就出現異常1-1中的warning以及Could not fetch URL https://pypi.org/simple/gensim/。
看起來貌似是證書的錯誤,后面又好像是URL來源的問題,那就換成國內的pip源試一試。默認的是:
pip install gensim -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com
然后就成功了。
然后驗證下吧。
有個小warning,根據提示再把這個安裝下就好了。
總結
Anaconda安裝package過程中出現的問題:
- 第一種,package安裝失敗:一般先使用conda install來安裝,如果失敗,就用pip install.一般是defaults里找不到合適的版本,使用pip鏡像就能找到。
- 第二種,package安裝成功但是無法import:這個可能和虛擬環境、依賴的包、Python設置、pip和pip3等有關系了。比如pip的SSL問題等。需要根據錯誤提示來操作。