当前位置: 代码网 > 服务器>服务器>Linux > 国内Linux服务器装Miniconda + pip/conda换源避坑指南

国内Linux服务器装Miniconda + pip/conda换源避坑指南

2026年09月30日 • Linux •我要评论
问题背景在一台 pop!_os(debian 系 linux)上下载 anaconda 安装包时,遇到以下现象:ping baidu.com 正常,网络出口没问题;清华 tuna / 中科大 ustc

问题背景

在一台 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/推荐,连通性好
北外 bfsuhttps://mirrors.bfsu.edu.cn/pypi/simple/推荐,兼容性强
清华 tunahttps://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 仍 403ip 级封禁,非 ua 问题同上,ua 伪装无效
阿里云 404该版本号未被归档换 latest 或换版本号
官方源 200 但慢境外带宽瓶颈换 miniconda 减小体积 + -c 断点续传

一句话:老版本 anaconda 在国内镜像站基本是"又老又难下",直接切 miniconda + 华为云/电信源,90% 的下载问题都能绕开。

以上就是国内linux服务器装miniconda + pip/conda换源避坑指南的详细内容,更多关于linux安装miniconda + pip/conda换源避坑的资料请关注代码网其它相关文章!

赞 (0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com