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的源下载,比较慢~

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