溫馨提示×

Ubuntu中PyTorch的安裝步驟是什么

小樊
47
2025-08-26 00:25:37
欄目: 智能運維

Ubuntu中安裝PyTorch有使用pip和conda兩種常用方法,以下是具體步驟:

使用pip安裝

  1. 更新系統包列表sudo apt update。
  2. 安裝Python和pipsudo apt install python3 python3-pip。
  3. 安裝PyTorch
    • CPU版本pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu。
    • GPU版本:先安裝對應CUDA版本,再運行pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu版本號,如pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117(CUDA 11.7版本)。
  4. 驗證安裝:在Python解釋器中輸入import torch,再輸入print(torch.__version__),若輸出版本號則安裝成功。

使用conda安裝

  1. 安裝Miniconda或Anaconda:從官網下載安裝包,按提示操作。
  2. 創建新環境conda create -n pytorch_env python=3.9(版本號可自定)。
  3. 激活環境conda activate pytorch_env。
  4. 安裝PyTorch
    • CPU版本conda install pytorch torchvision torchaudio cpuonly -c pytorch。
    • GPU版本conda install pytorch torchvision torchaudio cudatoolkit=版本號 -c pytorch,如conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch。
  5. 驗證安裝:在Python解釋器中輸入import torch,再輸入print(torch.__version__),若輸出版本號則安裝成功。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女