pip安装超时问题

默认情况下 pip 使用的是国外的镜像,在下载的时候速度非常慢,本文介绍2中处理方法

一)

1、设置超时时间

pip --default-timeout=1000 install -U 模块名

例如
pip --default-timeout=1000 install -U matplotlib
来下载matplotlib,让它的延迟检测时间变长。

2、使用镜像网址来代替

国内清华大学的源:https://pypi.tuna.tsinghua.edu.cn/simple

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

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

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

华为云:https://mirrors.huaweicloud.com/repository/pypi/simple

例如

pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple

 -i:指定镜像地址

这种只对当前安装对命令有用,如果需要全局修改,则需要修改配置文件。

Linux/Mac os 环境中,配置文件位置在 ~/.pip/pip.conf(如果不存在创建该目录和文件):

打开配置文件 ~/.pip/pip.conf,修改如下(可根据需要设置镜像源):

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = https://pypi.tuna.tsinghua.edu.cn

查看 镜像地址:

$ pip3 config list   
global.index-url='https://pypi.tuna.tsinghua.edu.cn/simple'
install.trusted-host='https://pypi.tuna.tsinghua.edu.cn'

Windows下,你需要在当前对用户目录下(C:\Users\xx\pip,xx 表示当前使用对用户,比如张三)创建一个 pip.ini在pip.ini文件中输入以下内容:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn

 

二)

升级pip版本

pip install --upgrade pip -i https://pypi.douban.com/simple

 

 

posted @ 2020-08-21 22:20  尘世风  阅读(354)  评论(0编辑  收藏  举报
*/