若PyTorch在Debian上安裝失敗,可按以下步驟排查解決:
檢查系統依賴
sudo apt update && sudo apt upgrade -ysudo 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)。參考來源: