There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘pypi.org‘,port=443)

在配置好anaconda環境後(如遇到conda指令無法安裝庫或者安裝較慢問題參見文末),想用pip install安裝相應的包(我這邊的示例安裝yacs這個庫),發現出現如下的錯誤:

Could not fetch URL https://pypi.org/simple/yacs/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/yacs/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)'))) - skipping
 

類似是你的電腦在打開pypi.org這個網站的時候提示有安全問題,報了證書相關的錯誤。

解決方法是你將該網站指定爲可信任就行了~

pip install --trusted-host pypi.org  安裝的包名字.whl

如果這之後還出現如下問題:

ERROR: Could not install packages due to an EnvironmentError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Max retries exceeded with url: /packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

那麼再把files.pythonhosted.org 設置成受信任就OK了。

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org 安裝的包名字.whl

至此,我這邊就不再報這個證書問題了~

 


 

在之前用conda指令安裝庫或者創建環境時遇到無法安裝(由於源的問題)的情況,在這也說下源配置的問題:

參考的文章很多,比如:anaconda conda 切換爲國內源  和 Anaconda 3 更換國內清華源教程(看不懂你打我)

我這邊在ubuntu下配置的condarc內容如下(其中#表示註釋掉了那行,網上很多源中地址是https,我這邊試了下http的成功了,算是提供參考,具體問題可參考上面兩篇鏈接)——

channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - http://mirrors.aliyun.com/pypi/simple/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/fastai/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
  #- defaults
show_channel_urls: true
#channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
#default_channels:
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
#  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
#custom_channels:
#  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
#  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
#  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
#  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
#  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
#  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

其中defaults建議註釋掉,默認是anaconda的源下載,比較慢~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章