Python 修改 pip 源為國內源
https://zhuanlan.zhihu.com/p/109939711
https://www.osgeo.cn/python-packaging/guides/installing-using-pip-and-virtual-environments.html
https://legacy.python.org/dev/peps/pep-0405/
在 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 源具體修改方式是,我們以安裝 python 的 markdown 模塊為例,通常的方式是直接在命令行運行
pip install markdown
這樣會從國外官網下載markdown模塊並安裝。
若要把 pip 源換成國內的,只需要把上面的代碼改成下圖這樣(下圖以清華大學源為例):
pip install markdown -i https://pypi.tuna.tsinghua.edu.cn/simple
這樣我們就從清華大學源成功安裝了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/
參考:
============== End