python安装第三方库慢?——更换Python pip库镜像地址

前言

一般安装python之后,pip默认的镜像地址是:https://pypi.org/simple 但是由于默认的官方pypi经常被墙,或者连接速度较慢,导致pip安装经常不可用或者下载安装包失败,所以我们最好是将自己使用的pip源更换一下,使用境内的pip镜像安装源。

网上有很多可用的源,例如:

清华大学:https://pypi.tuna.tsinghua.edu.cn/simple 清华大学的pip源是官网pypi的镜像,每隔5分钟同步一次,重点推荐!!!

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

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

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

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

临时使用镜像地址

在使用pip的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install [module] -i https://pypi.org/simple
pip install  -i https://pypi.org/simple -U [module]
#-U可有可无
#-U, --upgrade    Upgrade all specified packages to the newest available version. The handling of dependencies depends on the upgrade-strategy used
#将所有指定的包升级到最新的可用版本。依赖关系的处理取决于所使用的升级策略。

例如:

#安装最新版本tensorflow
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  -U tensorflow

永久修改pip镜像(推荐)

Linux系统:

修改 ~/.pip/pip.conf (没有就创建一个pip文件夹及pip.conf 文件。文件夹要加“.”,表示是隐藏文件夹),pip文件内容如下:

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

Windows系统:

直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,并新建文件pip.ini文件,pip文件内容如下:

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

在这里插入图片描述
在这里插入图片描述

发布了113 篇原创文章 · 获赞 105 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43124279/article/details/105410415