conda换源


conda换源

由于网络连接原因,使用 Anaconda 或 Miniconda 时,默认的官方源速度较慢。为提高下载速度,您可以将 Conda 的源更换为国内的镜像源。以下是详细的操作步骤:

1. 生成 .condarc 配置文件:

在 Windows 系统中,用户目录下可能没有 .condarc 文件。您可以通过以下命令生成该文件:

conda config --set show_channel_urls yes

执行后,.condarc 文件将被创建在用户主目录下。在 Windows 上,用户主目录通常位于 C:\Users\用户名\

2. 编辑 .condarc 文件:

使用文本编辑器打开 .condarc 文件,将其内容替换为以下内容:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
  msys2: https://mirrors.bfsu.edu.cn/anaconda/cloud
  bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
  menpo: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch-lts: https://mirrors.bfsu.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.bfsu.edu.cn/anaconda/cloud

上述配置将 Conda 的源更换为北京外国语大学的镜像站。您也可以选择其他国内镜像源,如清华大学、上海交通大学等。具体的镜像源配置可以参考清华大学开源软件镜像站的官方文档。

mirrors.tuna.tsinghua.edu.cn

3. 清理索引缓存:

更换源后,建议清理 Conda 的索引缓存,以确保使用新的镜像源:

conda clean -i

4. 测试新的源:

创建一个新的 Conda 环境,并安装一个包,以验证新的源是否生效:

conda create -n test_env numpy

如果安装过程顺利且速度较快,则说明源更换成功。

注意事项:

  • 备份原始配置: 在更改 .condarc 文件之前,建议备份原始配置,以防需要恢复。
  • 恢复默认源: 如果需要恢复默认源,可以删除 .condarc 文件,或者执行以下命令:
conda config --remove-key channels

通过以上步骤,您可以成功将 Conda 的源更换为国内镜像源,从而提高包的下载速度和稳定性。


文章作者: 0xdadream
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 0xdadream !
评论
  目录