下面分 “安装 Debian 系统上的 PyTorch” 和 “在 Debian 下推荐的安装方式” 两部分说明,适用于 Debian 11 / 12。
cat /etc/debian_version
python3 --version
Debian 12 默认是 Python 3.11,Debian 11 是 3.9
sudo apt update
sudo apt install -y python3-venv python3-pip
python3 -m venv pytorch-env
source pytorch-env/bin/activate
适合 无 NVIDIA 显卡 或只是学习使用:
pip install torch torchvision torchaudio
验证:
python -c "import torch; print(torch.__version__)"
nvidia-smi
sudo apt install -y nvidia-driver
重启后确认:
nvidia-smi
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
其他版本见:https://pytorch.org/get-started/locally/
验证:
python -c "import torch; print(torch.cuda.is_available())"
输出 True 即成功。
pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
✅ 使用 venv
❌ 避免 sudo pip install
import torch
x = torch.rand(3, 3)
print(x)
print("CUDA:", torch.cuda.is_available())
如果你告诉我:
我可以给你 更精确的一条命令安装方案。