温馨提示×

CentOS怎样升级PyTorch

小樊
60
2026-08-05 01:03:44
栏目: 智能运维

CentOS 上升级 PyTorch,常见做法取决于你最初是用 pip 还是 conda 安装的。下面分别说明,并给出注意事项(尤其是 CentOS 7/8 的兼容性问题)。


一、先确认当前环境

1️⃣ 查看当前 PyTorch 版本

python -c "import torch; print(torch.__version__)"

2️⃣ 查看安装方式

pip show torch

conda list torch

二、使用 pip 升级 PyTorch(最常见 ✅)

✅ 升级到最新稳定版

pip install --upgrade torch torchvision torchaudio

✅ 指定版本(推荐,避免兼容问题)

pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0

✅ 指定 CUDA 版本(非常重要)

如果你的机器有 NVIDIA GPU:

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

常见 CUDA 版本:

CUDA URL
CUDA 11.8 cu118
CUDA 12.1 cu121
CPU cpu

示例(CPU 版本):

pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

三、使用 conda 升级 PyTorch

✅ 升级到最新版

conda update pytorch torchvision torchaudio -c pytorch

✅ 指定版本

conda install pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 -c pytorch

✅ 指定 CUDA

conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia

四、CentOS 特别注意事项 ⚠️

1️⃣ CentOS 7 / glibc 版本过低

  • CentOS 7:glibc 2.17
  • PyTorch ≥ 2.0 需要 glibc ≥ 2.18~2.28

✅ 解决方案:

  • 使用 conda 环境(conda 自带新版 glibc)
  • 降级 PyTorch 版本,例如:
pip install torch==1.13.1 torchvision==0.14.1

2️⃣ GCC / libstdc++ 问题

报错示例:

GLIBCXX_3.4.30 not found

✅ 解决方案:

conda install -c conda-forge gcc_linux-64 gxx_linux-64

3️⃣ 显卡驱动 & CUDA

检查:

nvidia-smi
nvcc --version

⚠️ pytorch 使用的 CUDA 版本 ≠ 系统驱动 CUDA 版本

  • 驱动决定 最高可支持 CUDA
  • PyTorch 自带 运行时 CUDA

五、升级后验证 ✅

python -c "import torch; print(torch.__version__)"
python -c "print(torch.cuda.is_available())"

六、推荐方案总结

环境 建议
CentOS 7 ✅ conda + PyTorch 1.x/2.0
CentOS 8 / Rocky / Alma ✅ pip + CUDA 11.8
无 GPU ✅ CPU 版本

如果你愿意,可以告诉我:

  • ✅ CentOS 版本(7 / 8 / Stream)
  • ✅ Python 版本
  • ✅ 是否有 GPU(NVIDIA?)
  • ✅ 报错信息(如果升级失败)

我可以给你 一条最稳妥的命令

0