用了那么久Python,却不懂得切换国内镜像源,是不是有点尴尬?下面我来分享一下如何设置镜像源,作为一个懒人,只想一劳永逸,能简单就不去搞那些复杂的。
1.一条命令设置pip为国内源
以清华源为例子:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
设置后,如何查看是否成功呢?用如下命令进行查看
pip3 config list
2.设置conda为国内源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --setshow_channel_urls yes
3.一些国内的镜像源
有些人可能比较偏爱其他镜像源,这里列举几个:
豆瓣:http://pypi.douban.com/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
4. 还原为默认源
pip的话,可以运行下面的命令:
pip config unset global.index-url
conda的话,运行下面的命令:
conda config --remove-key channels