在 Debian 上配置 PyTorch 的完整步骤
一 环境准备
sudo apt update && sudo apt upgrade -ysudo apt install -y build-essential cmake git python3 python3-pip python3-devpython3 -m venv ~/venvs/pytorch && source ~/venvs/pytorch/bin/activateconda create -n pytorch python=3.10 -y && conda activate pytorch二 安装 PyTorch
pip install torch torchvision torchaudioconda install pytorch torchvision torchaudio cpuonly -c pytorchpip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121conda install pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch -c nvidia三 验证安装与常见问题
python3 - <<'PY' import torch print("torch:", torch.__version__) print("cuda available:", torch.cuda.is_available()) print("device count:", torch.cuda.device_count()) if torch.cuda.is_available(): print("current device:", torch.cuda.current_device()) print("device name:", torch.cuda.get_device_name(0)) PYpip install torch torchvision torchaudio -i https://pypi.tuna.tsinghua.edu.cn/simple(注意镜像可能滞后,GPU 版本建议优先使用官方源)。torch.cuda.is_available() 返回 True;必要时重装对应版本的 PyTorch(参考上节命令)。