Skip to content

conda / Anaconda 换国内镜像源加速

conda install 慢、创建环境卡在 Solving environment、下载包超时——换国内镜像能显著改善下载速度。核心是写好 .condarc 配置文件。

一、完整 .condarc(清华 TUNA 镜像)

编辑用户目录下的 ~/.condarc(Windows 为 C:\Users\你的用户名\.condarc),写入:

yaml
channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

这份配置覆盖了主频道、conda-forge、pytorch、bioconda 等常用云频道。

二、命令行方式(等效)

不想手写文件,也可以用命令添加:

bash
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes

三、清理缓存并验证

bash
# 清索引缓存,让新源生效
conda clean -i

# 验证配置
conda config --show channels

# 测试
conda create -n test python=3.11

四、其他镜像

mirrors.tuna.tsinghua.edu.cn 换成下列任一即可:

镜像域名
清华 TUNAmirrors.tuna.tsinghua.edu.cn
中科大mirrors.ustc.edu.cn
北外mirrors.bfsu.edu.cn

五、conda 与 pip 混用建议

  • 环境里既有 conda 又有 pip 包时,尽量先用 conda 装、再用 pip 补,减少冲突。
  • pip 也要换源,见 pip 国内镜像
  • 装 PyTorch 走 conda 频道见 pip 装 PyTorch 慢

常见问题

Q:换源后仍很慢,卡在 Solving environment?

  • Solving 慢多是依赖求解问题,不全是下载。可试 conda install -c conda-forge mamba,用 mamba 替代 conda 求解,快很多。

Q:报 CondaHTTPError / SSL?

  • 检查 .condarc 缩进(YAML 对缩进敏感);conda clean -i 后重试。

Q:conda-forge 的包下不到?

  • 确认 custom_channels 里配了 conda-forge 镜像(见方法一)。

小结

  • 写好 ~/.condarc,覆盖 main / conda-forge / pytorch 等频道。
  • 改完 conda clean -i 让新源生效。
  • Solving environment 慢用 mamba 提速,和换源是两回事。

本文仅供技术学习与研究,请遵守所在国家/地区法律法规。

本站为技术学习交流站点,与 GitHub, Inc. 无任何隶属或官方关系。所有内容仅供技术研究与学习,请遵守所在国家/地区的法律法规。