环境: conda/4.11.0 CPython/3.8.8 Windows/10
镜像源选用阿里云镜像站anaconda镜像:https://mirrors.aliyun.com/anaconda/
参考:https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#show-channel-urls-show-channel-urls

使用配置文件修改镜像源

  • 使用 conda info 命令查看 .condarc 配置文件位置(一般为 $env:userprofile/.condarc)

  • 在 PowerShell 中使用 notepad $env:userprofile/.condarc 命令,通过记事本打开 .condarc (若提示文件不存在,则点击创建)

  • CMD 中可以使用 notepad %userprofile%/.condarc 命令
  • 将以下内容填入 .condarc 文件中

    channels:
      - defaults
    show_channel_urls: true
    default_channels:
      - http://mirrors.aliyun.com/anaconda/pkgs/main
      - http://mirrors.aliyun.com/anaconda/pkgs/r
      - http://mirrors.aliyun.com/anaconda/pkgs/msys2
    custom_channels:
      conda-forge: http://mirrors.aliyun.com/anaconda/cloud
      msys2: http://mirrors.aliyun.com/anaconda/cloud
      bioconda: http://mirrors.aliyun.com/anaconda/cloud
      menpo: http://mirrors.aliyun.com/anaconda/cloud
      pytorch: http://mirrors.aliyun.com/anaconda/cloud
      simpleitk: http://mirrors.aliyun.com/anaconda/cloud
    

    https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#channel-locations-channels

  • channels 的 defaults 会引用 default_channels 中的 URL
  • show_channel_urls 显示下载内容的 URL
  • 使用命令行添加镜像源(失败)

    失败原因:custom_channels 的值添加失败;custom_channels 下有仍有键值对,为嵌套关系,但 --add 只能添加一个 key;尝试空格,引号,冒号,括号,斜杠等没有找到方法可以嵌套添加

    conda config --set show_channel_urls yes
    
    conda config --add default_channels http://mirrors.aliyun.com/anaconda/pkgs/msys2
    
    conda config --add default_channels http://mirrors.aliyun.com/anaconda/pkgs/r
    
    conda config --add default_channels http://mirrors.aliyun.com/anaconda/pkgs/main
    
    # conda config --add custom_channels conda-forge: http://mirrors.aliyun.com/anaconda/cloud
    # conda config --add custom_channels msys2: http://mirrors.aliyun.com/anaconda/cloud
    # conda config --add custom_channels bioconda: http://mirrors.aliyun.com/anaconda/cloud
    # conda config --add custom_channels menpo: http://mirrors.aliyun.com/anaconda/cloud
    # conda config --add custom_channels pytorch: http://mirrors.aliyun.com/anaconda/cloud
    # conda config --add custom_channels simpleitk: http://mirrors.aliyun.com/anaconda/cloud
    
  • 使用 conda config --remove channels http://mirrors.aliyun.com/anaconda/pkgs/r 移除相应配置
  • 清理索引缓存

    运行 conda clean -i 命令清除索引缓存,确保使用的是镜像站的索引。


  • 文章系个人学习总结,希望可以给大家带来些许启发,欢迎提出建议或给予指正。
  • 本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
  • 欢迎大家转载分享,转载请标明源地址,谢谢
  • 来源:零一魔法

    物联沃分享整理
    物联沃-IOTWORD物联网 » 配置 conda 镜像环境

    发表评论