在国内连接 Anaconda 官方源速度非常慢。用官方源去安装、升级包,速度估计会抓狂,说不定还总是失败。
解决方法很简单,只需要把官方镜像替换为国内的镜像。网上搜的教程一般是清华或者中科大源。不过,由于授权问题,中科大的 Anaconda 源已经停止服务。目前可以使用用清华或者北外的源。
添加清华源
以清华源为例:
添加仓库镜像:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
下面一些库可以根据需要添加,比如要用 R 语言的话增加 R 的镜像,要用 bioconda 则加上 bioconda的镜像:
# R
添加北外源
如果清华源无法使用,可以换成北外源,将地址 https://mirrors.tuna.tsinghua.edu.cn
换成 https://mirrors.bfsu.edu.cn
:
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
conda config --add channels https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
检查是否成功
添加后,可以查看目前的conda软件源,检查是否添加成功:
# 设置显示源的地址
清楚缓存
添加成功后,可以运行 conda clean -i
清除索引缓存,保证用的是镜像站提供的索引。
删除源
如果要删除不能用的源,把 --add
换成 --remove
即可,比如:
conda config --remove channels https://cernet.mirrors.ustc.edu.cn/anaconda/pkgs/free
小提示
文章会不定期修改,最新版可在 www.zhaozhuji.net 或者 www.cnblogs.com/shiyanhe 查看。