溫馨提示×

Ubuntu下PyTorch安裝步驟是什么

小樊
48
2025-08-24 00:34:32
欄目: 智能運維

以下是在Ubuntu下安裝PyTorch的步驟:

安裝前準備

更新系統包列表:sudo apt update。若需GPU支持,安裝NVIDIA顯卡驅動,可通過sudo apt install nvidia-driver-xxx(xxx為驅動版本號)安裝。同時,根據顯卡型號從NVIDIA官網下載安裝對應版本的CUDA工具包和cuDNN庫。

使用Conda安裝(推薦)

創建并激活虛擬環境:conda create -n pytorch_env python=3.8,conda activate pytorch_env。然后根據CUDA版本安裝PyTorch,如conda install pytorch torchvision torchaudio cudatoolkit=12.0 -c pytorch(12.0替換為實際CUDA版本)。

使用pip安裝

若不使用Conda,可先安裝pip:sudo apt install python3-pip。再根據CUDA版本選擇安裝命令,如pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu120(12.0替換為實際CUDA版本),不使用GPU則用pip install torch torchvision torchaudio。

驗證安裝

在Python解釋器中輸入import torch,print(torch.__version__)查看版本號,print(torch.cuda.is_available())檢查GPU是否可用。

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