在CentOS上更新PyTorch,你可以按照以下步驟進行:
打開終端:
升級pip(如果尚未安裝或需要更新):
pip install --upgrade pip
卸載舊版本的PyTorch(可選,但推薦):
pip uninstall torch torchvision torchaudio
安裝最新版本的PyTorch:
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
pip install torch torchvision torchaudio
如果你使用Anaconda或Miniconda管理Python環境,可以通過conda來安裝或更新PyTorch:
打開終端:
激活你的conda環境(如果有):
conda activate your_environment_name
更新conda(如果尚未安裝或需要更新):
conda update conda
卸載舊版本的PyTorch(可選,但推薦):
conda remove torch torchvision torchaudio
安裝最新版本的PyTorch:
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
無論使用哪種方法安裝,都可以通過以下命令驗證PyTorch是否安裝成功:
import torch
print(torch.__version__)
這將輸出當前安裝的PyTorch版本號。
通過以上步驟,你應該能夠在CentOS上成功更新PyTorch。