在Debian系统上管理PyTorch的不同版本可以通过以下几种方法实现:
sudo apt update sudo apt install python3-pip 安装特定版本的PyTorch:
pip3 install torch torchvision torchaudio pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu102 pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113 pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117 pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu120 更新PyTorch:
pip3 uninstall torch torchvision torchaudio pip3 install torch torchvision torchaudio 验证安装:
import torch print(torch.__version__) print(torch.cuda.is_available()) 安装Miniconda或Anaconda(如果尚未安装):
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh 创建并激活conda环境:
conda create -n pytorch_env python=3.8 conda activate pytorch_env 安装特定版本的PyTorch:
conda install pytorch torchvision torchaudio cpuonly -c pytorch conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch conda install pytorch torchvision torchaudio cudatoolkit=12.0 -c pytorch 更新PyTorch:
conda remove pytorch torchvision torchaudio cudatoolkit -n pytorch_env conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch 验证安装:
import torch print(torch.__version__) print(torch.cuda.is_available()) 创建虚拟环境:
python3 -m venv pytorch-env source pytorch-env/bin/activate 在虚拟环境中安装特定版本的PyTorch:
pip install torch torchvision torchaudio pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu102 切换虚拟环境:
source /path/to/other/pytorch-env/bin/activate 通过以上方法,你可以在Debian系统上灵活地管理PyTorch的不同版本,确保每个项目都能在隔离的环境中运行,避免版本冲突。