必须清空默认境外源再逐条添加清华镜像地址,否则因源冲突导致安装失败或降速;先执行conda config --remove-key channels清除channels配置项,再依次添加pkgs/free、pkgs/main、conda-forge三个清华源并启用show_channel_urls,最后用conda clean -i清理索引缓存以确保生效。

直接结论:必须清空默认境外源,再逐条添加清华镜像地址,否则会因源冲突导致安装失败或降速。
conda config --remove-key channels 必须先执行
Conda 默认自带 repo.anaconda.com 境外源,不清理就加国内源,它会按顺序查源——先连国外服务器超时,再 fallback 到国内,实际速度反而更慢。常见错误现象是:Solving environment... 卡死 10 分钟以上,或报错 ConnectionError: Failed to connect。
执行以下命令彻底清除所有已有源:
conda config --remove-key channels
注意:这条命令不会删除 .condarc 文件本身,只清掉 channels 配置项,安全可逆。
四条命令要逐条运行,顺序不能错
清华镜像站对 pkgs/main、pkgs/free、conda-forge 三个源做了独立镜像,缺一不可。尤其 conda-forge 是遥感、AI 等领域大量库(如 gdal、pytorch)的实际发布源,漏掉会导致 Package not found。
依次复制粘贴执行(每行回车一次):
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 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
最后一条让终端显示每个包从哪个源下载,方便排错。
Miniconda py314_26.5.3-2 Linux x86_64 安装脚本,来自 Anaconda 官方 Miniconda 下载目录,适合服务器、工作站和容器环境配置轻量 Conda 与 Python。
验证是否生效:看输出里有没有清华地址
运行命令检查配置结果:
conda config --show channels
正确输出应类似:
channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
如果还看到 https://repo.anaconda.com/ 或空行,说明前面 --remove-key channels 没成功,需重做。
另外,.condarc 文件位置要确认:Windows 在 C:\Users\<yourname>\.condarc</yourname>,Linux/macOS 在 $HOME/.condarc;若该文件不存在,conda config 命令会自动创建。
PyTorch / GDAL 等库装不上?可能是 conda-forge 同步延迟
清华镜像站不同步 pytorch-nightly、ignite-nightly 这类极新版本,也偶尔滞后几小时同步正式版。如果你明确需要某个最新版,但 conda install 找不到,可以临时指定源:
conda install -c conda-forge gdal
但不建议长期用 -c 临时加源,容易污染环境。更稳妥的做法是等几小时再试,或检查是否拼错了包名(比如 pytorch 不是 torch)。
真正容易被忽略的点是:镜像配置完必须执行 conda clean -i 清掉旧索引缓存,否则 Conda 还会拿过期的元数据去匹配,导致明明源对了却提示“no packages found”。

















