在Linux下更新PyTorch版本,可使用pip或conda工具,具体如下:
sudo apt-get install python3-pip安装。pip install --upgrade pip。pip install --upgrade torch torchvision torchaudio。若需指定版本,可在命令后添加对应版本号,如pip install torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0。conda update conda。conda list torch。conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia;CPU版本:conda install pytorch torchvision torchaudio cpuonly -c pytorch。更新前建议备份项目代码和数据,更新后可通过import torch; print(torch.__version__)验证安装是否成功。