PyTorch Linux版本更新指南
conda activate your_env(conda)或source your_env/bin/activate(venv)激活目标环境。python -c "import torch; print(torch.__version__)"。nvidia-smi查看显卡驱动支持的CUDA版本(如“12.2”);nvcc --version查看已安装的CUDA Toolkit版本(需与PyTorch版本匹配,参考PyTorch官网兼容性表)。pip uninstall torch torchvision torchaudio
此步骤可清除旧版本文件,避免残留文件导致冲突。
pip install --upgrade pip
确保pip为最新版本,提升安装稳定性。
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
pip install torch torchvision torchaudio
若需升级到特定版本(如1.13.0),可添加版本号:
pip install torch==1.13.0 torchvision==0.14.0 torchaudio==2.0.0
conda update conda
确保conda为最新版本,避免安装过程中的兼容性问题。
conda remove pytorch torchvision torchaudio -c pytorch
清除旧版本依赖,减少冲突风险。
conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch
conda install pytorch torchvision torchaudio cpuonly -c pytorch
若需升级到特定版本(如1.13.0),可添加版本号:
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==2.0.0 cudatoolkit=11.7 -c pytorch
安装完成后,通过以下命令确认PyTorch版本及CUDA可用性:
import torch
print("PyTorch版本:", torch.__version__) # 查看版本号
print("CUDA可用性:", torch.cuda.is_available()) # 检查GPU支持
if torch.cuda.is_available():
print("CUDA版本:", torch.version.cuda) # 查看CUDA版本
torchvision、torchaudio等关联库,避免版本冲突。sudo(不推荐在虚拟环境中使用),或使用--user参数安装到用户目录。