PIP换源的方式
在使用Python安装包工具pip
时经常会出现下载很慢的情况,这其中有很大一部分原因和pip
的源有关,在我们安装Python后,通常Python解释器自带pip这个工具,但是这里pip是设置的默认源,也就是官方源:https://pypi.org/simple
,这个源在国内的下载速度是很慢的,所以我们为了提高包的下载速度我们可以通过换源来实现。
PYPI国内源路径
- 阿里云 http://mirrors.aliyun.com/pypi/simple/
- 豆瓣(douban) http://pypi.douban.com/simple/
- 清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
- 中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
临时换源
#清华源
pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip install markdown -i https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip install markdown -i http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip install markdown -i http://pypi.douban.com/simple/
永久换源
Linux系统
- 在根目录下创建/修改
~/.pip/pip.conf
pip配置文件 - 进入文件新增/修改内容
[global]
index-url=http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
- 保存文件并退出;
Windows系统
- Windows在%HOMEPATH%\pip\pip.ini中修改上面第二步的内容;(例如:C:\Users\hp\AppData\Roaming\pip\pip.ini)
- 保存文件并退出
# 清华源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 阿里源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 腾讯源
pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple
# 豆瓣源
pip config set global.index-url http://pypi.douban.com/simple/# 换回默认源pip config unset global.index-url