以下是解決Debian上PyTorch安裝問題的步驟及方法:
更新系統并安裝基礎依賴
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip build-essential cmake git libopenblas-dev liblapack-dev
若需GPU支持,還需安裝NVIDIA驅動、CUDA和cuDNN。
選擇安裝方式
pip3 install torch torchvision torchaudio
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118/torch_stable.html
conda create -n pytorch_env python=3.8
conda activate pytorch_env
conda install pytorch torchvision torchaudio -c pytorch # CPU版本
conda install pytorch torchvision torchaudio pytorch-cuda11.8 -c pytorch -c nvidia # GPU版本
處理常見問題
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch torchvision
sudo
命令安裝系統級依賴。驗證安裝
進入Python環境運行以下代碼,檢查是否成功:
import torch
print(torch.__version__)
print(torch.cuda.is_available()) # 若為True則GPU支持正常
參考來源: