温馨提示×

Ubuntu PyTorch如何进行版本更新

小樊
45
2025-09-03 01:15:12
栏目: 智能运维

在Ubuntu上更新PyTorch版本,主要有以下两种方法:

  • 使用pip安装
    1. 打开终端,更新pip:pip install --upgrade pip
    2. 卸载旧版本:pip uninstall torch torchvision torchaudio
    3. 安装新版本:访问PyTorch官网,根据CUDA版本选择安装命令,如pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117(需CUDA 11.7);若无需GPU,可直接用pip install torch torchvision torchaudio
  • 使用conda安装
    1. 打开终端,更新conda:conda update conda
    2. 激活虚拟环境(若有):conda activate your_environment_name
    3. 卸载旧版本:conda remove pytorch torchvision torchaudio
    4. 安装新版本:根据CUDA版本选择命令,如conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch(需CUDA 11.7);无需GPU则用conda install pytorch torchvision torchaudio cpuonly -c pytorch

安装完成后,可通过import torch; print(torch.__version__)验证版本。

0