pip 安装库比较慢的解决方法(国内镜像)
作者:那一剑的風情 时间:2022-09-30 04:02:29
对于Python开发用户来讲,PIP安装软件包是家常便饭。但国外的源下载速度实在太慢,浪费时间。而且经常出现下载后安装出错问题。
所以把PIP安装源替换成国内镜像,可以大幅提升下载速度,还可以提高安装成功率。
国内源:
新版ubuntu要求使用https源,要注意。
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云: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 -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider,这样就会从清华这边的镜像去安装pyspider库。
永久修改,一劳永逸:
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[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。内容同上。
下面是补充:
场景
想安装 Django 库
在 cmd 敲入命令
pip install Django
但是发现下载安装文件非常慢
原因:实质访问的下载网站是 https://pypi.Python.org/simple/
这是一个国外网站,速度比较慢
解决办法
使用国内源
在 cmd 更改为敲入命令
# 豆瓣源
pip install Django -i https://pypi.douban.com/simple# 或者 清华大学源
pip install Django -i https://pypi.tuna.tsinghua.edu.cn/simple
以后使用 pip 时,都可以把 -i https://pypi.douban.com/simple 作为必填的末尾内容,能保证下载速度
来源:https://www.cnblogs.com/SZxiaochun/p/7347331.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
用60行代码实现Python自动抢微信红包
![](https://img.aspxhome.com/file/2023/0/90380_0s.png)
对python中Matplotlib的坐标轴的坐标区间的设定实例讲解
![](https://img.aspxhome.com/file/2023/4/103024_0s.jpg)
Python数据分析Numpy中常用相关性函数
![](https://img.aspxhome.com/file/2023/3/103473_0s.png)
Pytorch模型迁移和迁移学习,导入部分模型参数的操作
![](https://img.aspxhome.com/file/2023/5/94095_0s.jpg)
MySQL优化全攻略--相关数据库命令
Python模块的加载讲解
![](https://img.aspxhome.com/file/2023/9/78459_0s.png)
python出现RuntimeError错误问题及解决
![](https://img.aspxhome.com/file/2023/6/102906_0s.png)
python数据处理之如何修改索引和行列
![](https://img.aspxhome.com/file/2023/7/64647_0s.png)
asp如何在线修改数据库表?
解决杀毒软件误删asp文件的方法
php 异常处理实现代码
asp如何生成XML数据
Javascript将数值转换为金额格式(分隔千分位和自动增加小数点)
Python实现设置显示屏分辨率
![](https://img.aspxhome.com/file/2023/7/70867_0s.png)
简单的Python解密rsa案例
![](https://img.aspxhome.com/file/2023/9/65109_0s.png)
我的ImageMagick使用心得
![](https://img.aspxhome.com/file/UploadPic/200810/21/20081021122020655s.jpg)
sqlserver 多表查询不同数据库服务器上的表
彻底搞懂Python字符编码
![](https://img.aspxhome.com/file/2023/0/63510_0s.jpg)