在 CentOS 上升级 PyTorch,常见做法取决于你最初是用 pip 还是 conda 安装的。下面分别说明,并给出注意事项(尤其是 CentOS 7/8 的兼容性问题)。
python -c "import torch; print(torch.__version__)"
pip show torch
或
conda list torch
pip install --upgrade torch torchvision torchaudio
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0
如果你的机器有 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 update pytorch torchvision torchaudio -c pytorch
conda install pytorch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 -c pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
✅ 解决方案:
pip install torch==1.13.1 torchvision==0.14.1
报错示例:
GLIBCXX_3.4.30 not found
✅ 解决方案:
conda install -c conda-forge gcc_linux-64 gxx_linux-64
检查:
nvidia-smi
nvcc --version
⚠️ pytorch 使用的 CUDA 版本 ≠ 系统驱动 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 版本 |
如果你愿意,可以告诉我:
我可以给你 一条最稳妥的命令 ✅