使用pip install的时候我们经常发现下载的速度很慢,因为我们下载python库所使用的原地址是国外的,所以下载速度非常慢,有时还会因为下载超时而失败(经常失败,特别是网速不好的时候)
那么有没有一个更为简洁的方法去加快安装python库的速度呢?
答案是有的
平时最常用的方法是使用使用其他的源来加快下载速度:
- 阿里云:http://mirrors.aliyun.com/pypi/simple (推荐)
- 清华:https://pypi.tuna.tsinghua.edu.cn/simple (经常失败............失败到我怀疑人生了)
- 豆瓣:http://pypi.douban.com/simple
- 中国科技大学 Simple Index
- 华中理工大学:http://pypi.hustunique.com/
- 山东理工大学:http://pypi.sdutlinux.org/
临时修改:
使用命令:
pip install (库名) -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
1、pip install 库名老规矩没有变化
2、-i http://pypi.douban.com/simple: 需要的源链接
3、--trusted-host pypi.douban.com: 信任该源
清华和阿里云的更换2和3中的链接就好了
一劳永逸:
首先,你需要确定,你的电脑配置里面有没有pip.conf文件,
可以
locate pip.conf
我的电脑是有这个文件的,对应位置是
/home/aaa/.config/pip/pip.conf
所以我直接修改就好了.没有的话,你也可以在.config/pip/pip.conf这个路径下新建一个pip.conf文件,直接
gedit /home/aaa/.config/pip/pip.conf
不管你有没有这个文件,都会新建或者直接打开的哟.主要是你要确定自己的路径,也就是确定aaa在你的电脑中是什么路径名.
好了,在pip.conf中加入
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
[install]
trusted-host=mirrors.aliyun.com
然后,再正常的pip install就好了.这样,每次都会自动去阿里的镜像中下载安装了~
速度那是杠杠滴~~~~嗖嗖嗖的了
其他:
//安装特定版本,被坑了好多次,这次长记性了
pip --default-timeout=100 install tensorflow==2.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
//pip 更新版本
python -m pip install --upgrade pip