美文网首页
镜像也有可能出问题

镜像也有可能出问题

作者: SSSimonYang | 来源:发表于2020-08-10 19:26 被阅读0次

    本文基于windows,所有类似<your_user_name>的字段需要自行进行替换。

    在使用python和R时,经常需要安装包,包的官方服务器在国外,我们一般选择配置国内镜像来解决下载速度问题。

    国内镜像最常用的是清华的tuna镜像:

    image-20200719101931008

    可以看出,清华镜像提供了计算机领域的常用安装包下载以及常用镜像。

    我的anaconda和R就使用了清华镜像。

    anaconda

    修改或新建C:\Users\<your_user_name>\.condarc

    内容为:

    channels:
      - defaults
    show_channel_urls: true
    channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
    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
      - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
    custom_channels:
      conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
      simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
    

    R

    修改C:\Program Files\R\R-3.6.1\etc\Rprofile.site

    options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
    options(BioC_mirror="https://mirrors.tuna.tsinghua.edu.cn/bioconductor")
    options(url.method='libcurl')
    options(download.file.method = 'libcurl')
    

    这里还修改了下载包的网络协议,不然win上下载包可能出现问题。

    anaconda syncing

    周五上午我用conda安装包的时候,出现了如下错误:

    Collecting package metadata (current_repodata.json): done
    Solving environment: failed with initial frozen solve. Retrying with flexible solve.
    Collecting package metadata (repodata.json): failed
    

    后面还有很长,就不放了,观察一下具体error是OpenSSL.SSL.WantReadError。conda之前一直都没有问题,怎么突然出问题,百度了这个错误,网上居然也没有特别相关的内容,一脸懵逼。之后我就随缘式的打开了清华镜像网站。

    QQ截图20200717104650

    咦,syncing,这个就有点意思了,看来极有可能是因为这个镜像目前正在同步,所以不能使用。那么我就要考虑使用原始的国外镜像。

    临时修改我的配置文件

    default_channels:
      - https://repo.continuum.io/pkgs/main
      - https://repo.continuum.io/pkgs/free
      - https://repo.continuum.io/pkgs/r
    

    repo.continuum.io是anaconda官方镜像,修改之后再conda安装就好了。

    如果不想这么麻烦,而且知道包具体在哪个channel的话,可以使用

    conda install <package_name> --channel https://repo.continuum.io/pkgs/main
    

    不过如果conda在使用该指定channel找不到包的时候,会自动继续查找default_channels里的channel,当清华正在同步时,依旧会出现error。

    后来发现十几分钟后syncing就结束了,之后的默认安装一切正常,看来我不该起这么早工作。

    CRAN syncing

    今天上午,我又随缘的打开了清华镜像网站,突然看到R的镜像cran正在syncing

    QQ截图20200719094510

    不如测试下R安装会出现什么问题,没想到居然成功了,然后再打开清华镜像网站,发现同步已经结束,真的巧。

    如果你没这么巧又急着安装包的话,可以指定镜像:

    install.packages('<package_name',repos='https://cloud.r-project.org/')
    

    r-project是官方镜像,直接打开cloud.r-project.org可以看到镜像列表,选择一个国内其他镜像也可。R在安装包时如果指定了镜像,在该镜像尝试失败时不会尝试repos里的已存镜像,和python有些不同。

    感想

    同步镜像一般发生在凌晨,结束在早上,如果你碰巧起了个大早又要安装包,有可能遇到我这种问题。希望我的推文能够帮助到你。

    相关文章

      网友评论

          本文标题:镜像也有可能出问题

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