美文网首页Python
处女座如何优化conda镜像的体验

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

作者: CiaoMrOtter | 来源:发表于2017-11-18 00:27 被阅读0次

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

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呈现。经过几个包的安装和更新,官方源很快就被镜像版本替换,界面整齐简练。

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

相关文章

网友评论

    本文标题:处女座如何优化conda镜像的体验

    本文链接:https://www.haomeiwen.com/subject/nzpsvxtx.html