debian

Debian下PyTorch的安装教程有哪些

小樊
49
2025-08-26 10:52:47
栏目: 智能运维

以下是在Debian下安装PyTorch的教程:

使用pip安装

  1. 更新系统包列表sudo apt update
  2. 安装Python和pipsudo apt install python3 python3-pip
  3. 安装PyTorch
    • CPU版本pip3 install torch torchvision torchaudio
    • GPU版本:先安装对应CUDA和cuDNN,再执行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版本)。

使用conda安装

  1. 安装Miniconda:从官网下载安装包安装,如bash Miniconda3-latest-Linux-x86_64.sh
  2. 创建并激活环境conda create -n pytorch_env python=3.9conda activate pytorch_env
  3. 安装PyTorch
    • CPU版本conda install pytorch torchvision torchaudio cpuonly -c pytorch
    • GPU版本conda install pytorch torchvision torchaudio cudatoolkit=<cuda_version> -c pytorch,如conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch(CUDA 11.7版本)。

安装完成后,可通过import torchprint(torch.__version__)print(torch.cuda.is_available())验证安装是否成功。

0
看了该问题的人还看了