在Debian上配置PyTorch环境,可参考以下步骤:
更新系统包:sudo apt update
,sudo apt upgrade
。安装Python和pip:sudo apt install python3 python3-pip
。
使用venv
模块创建,如python3 -m venv pytorch_env
,然后激活环境:source pytorch_env/bin/activate
。
pip install torch torchvision torchaudio
;若用GPU版本,需根据CUDA版本选择,如CUDA 11.7版本可执行pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
。conda create -n pytorch_env python=3.8
,conda activate pytorch_env
。安装CPU版本可执行conda install pytorch torchvision torchaudio cpuonly -c pytorch
;安装GPU版本可执行conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
(需提前安装对应CUDA和cuDNN)。在Python环境中执行import torch
,print(torch.__version__)
,print(torch.cuda.is_available())
。若显示版本号且cuda.is_available()
返回True
(GPU版本),则安装成功。