欢迎访问我的博客原文:
https://huaxiaostar.com/2019/01/python-pip-china/
Python 里经常要安装各种这样的包,安装各种包时最常用的就是 pip,pip 默认从官网下载文件,官网位于国外,下载速度时快时慢,还经常断线,国内的体验并不太好。
解决办法是把 pip 源换成国内的。
最常用的并且可信赖的源包括清华大学源、豆瓣源、阿里源等:pypi 清华大学源:https://pypi.tuna.tsinghua.edu.cn/simple
pypi 豆瓣源 :http://pypi.douban.com/simple/
pypi 腾讯源:http://mirrors.cloud.tencent.com/pypi/simple
pypi 阿里源:https://mirrors.aliyun.com/pypi/simple/
pip 源具体修改方式:pip install markdown
这样会从国外源下载 markdown 模块并安装。
若要把 pip 源换成国内的,只需要把上面的代码改成如下(以清华大学源为例):pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple
以安装 python 的 markdown 模块为例,正常安装的命令是:
这样就从清华大学源成功安装了 markdown 模块,速度比 pip 默认的国外源快很多。
上述做法是“临时”改成国内源,如果不想每次用 pip 都加上 -i https://pypi.tuna.tsinghua.edu.cn/simple,那么可以把国内源设为默认,做法是:# 清华源
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/
欢迎访问我的博客原文:
https://huaxiaostar.com/2019/01/python-pip-china/