问题背景
在一台 pop!_os(debian 系 linux)上下载 anaconda 安装包时,遇到以下现象:
ping baidu.com正常,网络出口没问题;- 清华 tuna / 中科大 ustc 镜像返回 403 forbidden,即使加了浏览器 user-agent 也无效;
- 阿里云镜像返回 404 not found;
- 官方源
repo.anaconda.com返回 200 ok,但速度仅 122kb/s。
核心原因:数据中心 / 机房出口 ip 被部分国内镜像站做了 ip 级风控,ua 伪装无效;而阿里云根本没归档 anaconda3-5.3.1 这个老版本,所以 404。解决方案不是死磕老版本,而是换轻量 miniconda + 换对源。
一、为什么不要装 anaconda3-5.3.1
| 问题 | 说明 |
|---|---|
| 版本过老 | 2018 年发布,自带 python 3.7,已停止安全更新 |
| 体积过大 | 637mb,在 122kb/s 下要 89 分钟 |
| 冗余严重 | 预装几百个科学计算包,离线迁移场景根本用不上 |
| 镜像归档缺失 | 阿里云、部分镜像已不再保留该版本 |
正确做法:装 miniconda(约 90mb,体积只有 1/7),然后按需 conda create 环境。对后续的 conda-pack 离线迁移流程零影响。
二、miniconda 下载(按优先级试)
# 方案1:华为云镜像(数据中心 ip 友好) wget https://repo.huaweicloud.com/anaconda/miniconda/miniconda3-latest-linux-x86_64.sh # 方案2:腾讯云镜像 wget https://mirrors.cloud.tencent.com/anaconda/miniconda/miniconda3-latest-linux-x86_64.sh # 方案3:官方源(已确认 200,加 -c 断点续传) wget -c https://repo.anaconda.com/miniconda/miniconda3-latest-linux-x86_64.sh # 方案4:aria2c 多线程加速官方源 aria2c -x 16 -s 16 https://repo.anaconda.com/miniconda/miniconda3-latest-linux-x86_64.sh
安装:
bash miniconda3-latest-linux-x86_64.sh # 装完后重载 shell 或执行 source ~/.bashrc
三、conda 换源
3.1 先清旧配置
conda config --remove-key channels conda clean -i
3.2 推荐:华为云镜像
编辑 ~/.condarc:
channels: - defaults show_channel_urls: true default_channels: - https://repo.huaweicloud.com/anaconda/pkgs/main - https://repo.huaweicloud.com/anaconda/pkgs/r - https://repo.huaweicloud.com/anaconda/pkgs/msys2 custom_channels: conda-forge: https://repo.huaweicloud.com/anaconda/cloud pytorch: https://repo.huaweicloud.com/anaconda/cloud channel_priority: strict
验证:
conda clean -i conda create -n test numpy -y conda remove -n test --all -y
3.3 备选:纯 conda-forge + 清华云
channels: - conda-forge - nodefaults show_channel_urls: true custom_channels: conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud channel_priority: strict
注意:nodefaults 会阻止回落到 anaconda 官方仓库,只能装 conda-forge 里有的包。
3.4 注意事项
- 不要用旧教程里的
anaconda/pkgs/free,已废弃。 - 阿里云
anaconda/目录大量版本 404,不适合做 conda 主源。 - 改完源必须跑
conda clean -i,否则旧索引会干扰解析。
四、pip 换源
4.1 永久换源(推荐)
pip config unset global.index-url pip config unset global.trusted-host # 主源:中国电信 pip config set global.index-url https://mirrors.ctyun.cn/pypi/simple/ pip config set global.trusted-host mirrors.ctyun.cn # 备用源:北外 bfsu pip config set global.extra-index-url "https://mirrors.bfsu.edu.cn/pypi/simple/"
验证:
pip config list
4.2 临时换源(单次生效)
pip install requests -i https://mirrors.ctyun.cn/pypi/simple/ --trusted-host mirrors.ctyun.cn
4.3 手动配置文件(批量部署)
linux 路径 ~/.config/pip/pip.conf:
[global] index-url = https://mirrors.ctyun.cn/pypi/simple/ extra-index-url = https://mirrors.bfsu.edu.cn/pypi/simple/ timeout = 120 retries = 5 [install] trusted-host = mirrors.ctyun.cn mirrors.bfsu.edu.cn
4.4 常用 pip 源速查(2026 实测)
| 源 | 地址 | 状态 |
|---|---|---|
| 中国电信 | https://mirrors.ctyun.cn/pypi/simple/ | 推荐,连通性好 |
| 北外 bfsu | https://mirrors.bfsu.edu.cn/pypi/simple/ | 推荐,兼容性强 |
| 清华 tuna | https://pypi.tuna.tsinghua.edu.cn/simple | 部分 ip 403/robots 拦截 |
| 阿里云 | https://mirrors.aliyun.com/pypi/simple/ | 高峰期偶有超时 |
| 华为云 | https://repo.huaweicloud.com/repository/pypi/simple | 偶有解析/限流 |
| 豆瓣 | https://pypi.doubanio.com/simple/ | 新增 robots 拦截,不推荐 |
注意:extra-index-url 会让 pip 在多个源里搜同名包并取最高版本,私有包/内部源场景慎用,可能产生依赖混淆。
五、完整流程
# 1. 下载 miniconda wget https://repo.huaweicloud.com/anaconda/miniconda/miniconda3-latest-linux-x86_64.sh # 2. 安装 bash miniconda3-latest-linux-x86_64.sh source ~/.bashrc # 3. 配 conda 源(见上文 ~/.condarc) # 4. 配 pip 源(见上文 pip config set) # 5. 建环境 conda create -n llama-factory python=3.10 -y conda activate llama-factory # 6. 装依赖 pip install -r requirements.txt # 7. 验证 python -c "import torch; print(torch.__version__)" # 8. 打包离线迁移 conda activate base conda install -c conda-forge conda-pack -y conda pack -n llama-factory -o llama-factory.tar.gz
六、排查思路总结
| 现象 | 真实含义 | 解法 |
|---|---|---|
| ping 通但 wget 403 | 出口 ip 被镜像站风控 | 换源(华为云/电信)或走官方源 |
| 加了 ua 仍 403 | ip 级封禁,非 ua 问题 | 同上,ua 伪装无效 |
| 阿里云 404 | 该版本号未被归档 | 换 latest 或换版本号 |
| 官方源 200 但慢 | 境外带宽瓶颈 | 换 miniconda 减小体积 + -c 断点续传 |
一句话:老版本 anaconda 在国内镜像站基本是"又老又难下",直接切 miniconda + 华为云/电信源,90% 的下载问题都能绕开。
以上就是国内linux服务器装miniconda + pip/conda换源避坑指南的详细内容,更多关于linux安装miniconda + pip/conda换源避坑的资料请关注代码网其它相关文章!
发表评论