在 Linux 上升级 PyTorch 版本,常见做法取决于你使用的**包管理器(pip 或 conda)**以及是否有 GPU(CUDA) 需求。下面按场景说明。
python -c "import torch; print(torch.__version__)"
pip install --upgrade torch torchvision torchaudio
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0
pip install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
常见 CUDA 版本:
cu118→ CUDA 11.8cu121→ CUDA 12.1cpu→ 仅 CPU
conda list torch
conda update pytorch torchvision torchaudio -c pytorch
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia
避免系统环境混乱:
# 创建环境
conda create -n torch_env python=3.10
conda activate torch_env
# 安装
pip install torch torchvision torchaudio
python -c "import torch; print(torch.__version__); print(torch.cuda.is_available())"
torch.cuda.is_available() 为 True 表示 GPU 可用先卸载再安装:
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio
确认使用的 pip:
which python
which pip
如果你能告诉我:
我可以给你精确的一条命令。