PyTorch Linux庫更新指南
conda activate your_env
(conda)或source your_env/bin/activate
(venv)激活目標環境。pip uninstall torch torchvision torchaudio
此步驟可徹底清除舊版本文件,避免殘留依賴沖突。
pip install --upgrade pip
確保pip能正確解析最新版PyTorch的安裝包。
pip install --upgrade torch torchvision torchaudio
pip install --upgrade torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
替換cu117
為你的CUDA版本(如cu118
對應CUDA 11.8),可從PyTorch官網獲取對應命令。python -c "import torch; print(torch.__version__)"
輸出結果應為最新版本號(如2.1.0)。
conda update conda
確保conda能正確解析PyTorch依賴。
conda remove pytorch torchvision torchaudio cudatoolkit
清除舊版本及關聯的CUDA工具包,避免依賴沖突。
conda install pytorch torchvision torchaudio cpuonly -c pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
替換11.7
為你的CUDA版本,確保與GPU驅動兼容。conda list torch
輸出結果中的torch
版本號應為最新。
pip install torch==old_version
或conda install pytorch=old_version
回滾到指定版本。