Windows使用pip安装pipenv工具或者第三方库出现SSLError报错完美解决方法

今天博主我使用pip安装pipenv工具搞了半天总是报错:

C:\Users\23521\pipenv>pip install pipenv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pipenv/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pipenv/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pipenv/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pipenv/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pipenv/
Could not fetch URL https://pypi.org/simple/pipenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pipenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
ERROR: Could not find a version that satisfies the requirement pipenv (from versions: none)
ERROR: No matching distribution found for pipenv
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

不管我去网上怎么找资料去改,都还是这样的错误,就很Cd,后来终于找到了比较好的方法,出现这种SSL错误原因在于:

1.我们默认用的是国外的源(这个肯定,编程基本上来自于国外),
太远了嘛,而且又有墙墙,导致连接不太好,因此出现SSL错误,因此换个源就行了:
首先直接在C盘的user目录中创建一个pip目录,然后在这个文件夹中创建一个pip.ini文件(把文件后缀改一下就行),然后写入:

[global]

index-url = http://pypi.douban.com/simple

大家可以根据自己兴趣来,有很多国内源,上面那个是豆瓣的:

阿里云 http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

豆瓣 http://pypi.douban.com/simple

Python官方 https://pypi.python.org/simple/

v2ex http://pypi.v2ex.com/simple/

中国科学院 http://pypi.mirrors.opencas.cn/simple/

清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/

2.之后换完源,可能还会出现错误:

Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Requirement already up-to-date: pip in c:\users\23521\anaconda3\lib\site-packages (20.0.1)

没关系,这个是由于换源之后对源地址的不信任,因此在上述的pip.ini文件中后面再加上:

[install]

trusted-host=http://pypi.douban.com/simple

综上,即:

[global]

index-url = http://pypi.douban.com/simple

[install]

trusted-host=http://pypi.douban.com/simple

之后保存文件,然后在输入pip命令安装第三方库或者pipenv就可以成功了。

你可能感兴趣的:(Python)