在 CentOS 上“重装 PyTorch”通常分为几种情况,下面按最常见、最安全的方式给你说明。
先看看你原来是怎么装的:
pip show torch
或(如果你用 conda):
conda list torch
pip uninstall torch torchvision torchaudio -y
pip install torch torchvision torchaudio
先确认 CUDA 版本:
nvidia-smi
例如 CUDA 11.8:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
conda uninstall pytorch torchvision torchaudio
conda install pytorch torchvision torchaudio cpuonly -c pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
CentOS 7 可能报错:
GLIBC_2.17 not found
解决:
sudo yum install -y python3-devel gcc
python -c "import torch; print(torch.__version__)"
如果有 GPU:
python -c "import torch; print(torch.cuda.is_available())"
如果你愿意,可以告诉我:
我可以给你精准命令。