处女座如何优化conda镜像的体验

国内的同学通常已经在使用清华大学开源软件镜像站替代官方默认源了,简单几步即可缓解"访问便秘"的痛点:

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/
conda config --set show_channel_urls yes
#Conda Forge
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
#msys2
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
#bioconda
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
#menpo
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/

在使用类似conda install numpy这样的命令来进行常规安装更新的时候,通常会优先访问上述镜像进行安装和更新,非常便捷。

但是,

这时候会出现两个小问题:

  1. 处女座们不想看到长长一串镜像网址在终端换行破坏美观,但是又需要知道安装包的channel来源;
  2. 在部分package的安装需要指定channel;或是想通过指定channel加快访问速度时,conda反而会优先访问默认源而非镜像;

优化方法

首先设置channel alias:通过conda config --show可以看到,默认情况下的channel_alias值是https://conda.anaconda.org/, 对于任何非url形式的channel,诸如bioconda, conda-forge, 都会通过channel_alias替换成https://conda.anaconda.org/bioconda, https://conda.anaconda.org/conda-forge等完整地址(开发者也知道地址太长很难看的嘛),那这样的话我们在上面设置的镜像不就白搭了么!所以我们要对它进行替换:

conda config --set channel_alias https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

此后再进行conda install -c bioconda git等命令时,就能自动解析为https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda,也就是镜像所在地址!

但这仅对第三方源有效,默认的channel(default_channels)依然是官方的地址,于是继续深度设定。不过由于没法用命令添加默认频道,这里直接打开用户配置文件~/.condarc添加如下地址(你会发现刚才设置的channel_alias也出现在了这里,所以实际上只要遵照格式规范,直接在本配置文件中设定也是一样的):

default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r/
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro/

清华镜像站只提到了mainfree,其实rpro也有哦。

如此一来,channels 中的defaults源就被完全替换成了镜像站点。

看看效果

此时再进行安装时,会看到:

$ onda install -c bioconda bioconductor-biocinstaller
Fetching package metadata ...................
Solving package specifications: .

Package plan for installation in environment /Users/Cino/anaconda3:

The following NEW packages will be INSTALLED:

    bioconductor-biocinstaller: 1.28.0-r3.4.1_0  bioconda

The following packages will be UPDATED:

    jpeg:                       8d-2             defaults                            --> 9b-2             conda-forge
    libedit:                    3.1-hb4e282d_0   https://repo.continuum.io/pkgs/main --> 3.1.20170329-0   conda-forge
    libtiff:                    4.0.6-2          defaults                            --> 4.0.8-0          conda-forge
    pillow:                     3.4.2-py36_0     defaults                            --> 4.2.1-py36_0     defaults
    r:                          3.3.2-r3.3.2_0   conda-forge                         --> 3.4.1-r3.4.1_0   defaults
    r-base:                     3.3.2-0          defaults                            --> 3.4.1-0          defaults
    r-boot:                     1.3_18-r3.3.2_0  conda-forge                         --> 1.3_18-r3.4.1_0  conda-forge
    r-class:                    7.3_14-r3.3.2_0  conda-forge                         --> 7.3_14-r3.4.1_0  conda-forge
    r-cluster:                  2.0.6-r3.3.2_0   conda-forge                         --> 2.0.6-r3.4.1_0   conda-forge
    r-codetools:                0.2_15-r3.3.2_0  conda-forge                         --> 0.2_15-r3.4.1_0  conda-forge
    r-foreign:                  0.8_67-r3.3.2_0  conda-forge                         --> 0.8_67-r3.4.1_0  conda-forge
    r-kernsmooth:               2.23_15-r3.3.2_0 conda-forge                         --> 2.23_15-r3.4.1_0 conda-forge
    r-lattice:                  0.20_34-r3.3.2_0 conda-forge                         --> 0.20_34-r3.4.1_0 conda-forge
    r-mass:                     7.3_45-r3.3.2_0  conda-forge                         --> 7.3_45-r3.4.1_0  conda-forge
    r-matrix:                   1.2_7.1-r3.3.2_0 conda-forge                         --> 1.2_7.1-r3.4.1_0 conda-forge
    r-mgcv:                     1.8_17-r3.3.2_0  conda-forge                         --> 1.8_17-r3.4.1_0  conda-forge
    r-nlme:                     3.1_131-r3.3.2_0 conda-forge                         --> 3.1_131-r3.4.1_0 conda-forge
    r-nnet:                     7.3_12-r3.3.2_0  conda-forge                         --> 7.3_12-r3.4.1_0  conda-forge
    r-recommended:              3.3.2-r3.3.2_0   conda-forge                         --> 3.4.1-r3.4.1_0   defaults
    r-rpart:                    4.1_10-r3.3.2_0  conda-forge                         --> 4.1_10-r3.4.1_0  conda-forge
    r-spatial:                  7.3_11-r3.3.2_0  conda-forge                         --> 7.3_11-r3.4.1_0  conda-forge
    r-survival:                 2.40_1-r3.3.2_0  conda-forge                         --> 2.40_1-r3.4.1_0  conda-forge

The following packages will be SUPERSEDED by a higher-priority channel:

    ncurses:                    6.0-ha932d30_1   https://repo.continuum.io/pkgs/main --> 5.9-10           conda-forge
    readline:                   7.0-h81b24a6_3   https://repo.continuum.io/pkgs/main --> 7.0-0            conda-forge

Proceed ([y]/n)?

原本官方源变成了完整的地址(https://repo.continuum.io/pkgs/main),而镜像站点则以简洁的bioconda呈现。经过几个包的安装和更新,官方源很快就被镜像版本替换,界面整齐简练。

非常清爽呢。果然是个不务正业的强迫症……

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,067评论 19 139
  • 科多大数据带你来看,python工具Anaconda 安装配置。 序 Python易用,但用好却不易,其中比较头疼...
    大数据在说话阅读 3,972评论 1 22
  • Anaconda使用总结 原文出处:2016.7.19 PeterYuan 序 Python易用,但用好却不易,其...
    MiracleJQ阅读 2,227评论 0 11
  • 1. 介绍 任何语言的包,依赖和环境管理:Python,R,Ruby,Lua,Scala,Java,Javascr...
    Himryang阅读 74,520评论 6 67
  • 文:唐小糖 宝贝,此时此刻,你已经陪妈妈度过了三个春节。春节是中国人最重视的节日,妈妈出生的这三十多年,不论在哪里...
    唐小糖1982阅读 511评论 0 1