若PyTorch在Debian上安装失败,可按以下步骤排查解决:
检查系统依赖
sudo apt update && sudo apt upgrade -y
sudo apt install -y build-essential cmake git python3-dev python3-pip
。更换安装源
pip install torch torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
或配置conda清华源。版本兼容性检查
nvcc --version
检查CUDA版本,安装对应PyTorch版本(如CUDA 11.8对应cu118
)。安装方式选择
conda create -n pytorch_env python=3.8
conda activate pytorch_env
conda install pytorch torchvision -c pytorch # CPU版本
conda install pytorch torchvision cudatoolkit=11.8 -c pytorch -c nvidia # GPU版本
```。
pip install torch==2.2.1+cu118 torchvision==0.17.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118
```。
权限与环境变量
--user
参数或使用sudo
。export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
```。
离线安装(网络受限时)
.whl
文件:pip download torch torchvision -d ./pytorch_packages --index-url https://download.pytorch.org/whl/cu118
pip install --no-index --find-links=./pytorch_packages torch torchvision
```。
错误排查
ModuleNotFoundError
,手动安装缺失依赖(如pip install typing_extensions
)。参考来源: