以下是在Debian下安裝PyTorch的教程:
sudo apt update
。sudo apt install python3 python3-pip
。pip3 install torch torchvision torchaudio
。pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu<cuda_version>
,如pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
(CUDA 11.7版本)。bash Miniconda3-latest-Linux-x86_64.sh
。conda create -n pytorch_env python=3.9
,conda activate pytorch_env
。conda install pytorch torchvision torchaudio cpuonly -c pytorch
。conda install pytorch torchvision torchaudio cudatoolkit=<cuda_version> -c pytorch
,如conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
(CUDA 11.7版本)。安裝完成后,可通過import torch
,print(torch.__version__)
,print(torch.cuda.is_available())
驗證安裝是否成功。