pip换源


一:引言

在用pip命令安装时,有时候会出现这样的报错

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool
(host='pypi.tuna.tsinghua.edu.cn', port=443): Read timed out. (read timeout=15)")': /simple/asn1crypto/

image-20200710153009646

image-20200710153009646

这是因为默认的pip源是在国外的,连接错误或者丢包了,这时候就需要更换pip源了

二:pip源

1.在国内的pip源有以下几个:

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

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

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

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

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

三:一次性使用

1.使用格式:

 
pip install [要安装的] -i [pip源] --trusted-host [pip源https://之后,/simple/之前的内容]

2.比如说:要用阿里云的pip源安装django

 
pip install django -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

pip install django -i https://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn
pip install django -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install django -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
pip install django -i http://pypi.mirrors.ustc.edu.cn/simple/ --trusted-host pypi.mirrors.ustc.edu.cn

四:永久使用

1.打开文件管理器,在路径地址栏输入%APPDATA%

image-20200716132321130

image-20200716132321130

2.此时会进入C:Users电脑用户AppDataRoaming文件夹中,新建一个文件夹,命名为pip

image-20200716132429037

image-20200716132429037

3.进入pip文件夹,新建一个文本文档,重命名为pip.ini,右键 - 编辑

image-20200716132758989

image-20200716132758989

4.输入下列代码,然后保存,关闭

 
[global]
index-url = http://pypi.douban.com/simple
[install]
use-mirrors =true
mirrors =http://pypi.douban.com/simple/
trusted-host =pypi.douban.com

image-20200716132910274

 
 
 
原文地址:https://www.cnblogs.com/yding/p/13336186.html