Ubuntu下PyTorch库更新方法
Ctrl + Alt + T启动终端。pip install --upgrade pip,确保pip为最新版本,避免安装兼容性问题。pip show torch,查看当前安装的版本及安装路径。pip uninstall torch torchvision torchaudio,按提示确认卸载。pip install --upgrade torch torchvision torchaudio。pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117(需根据显卡驱动支持的CUDA版本调整,可通过nvcc --version查看当前CUDA版本)。pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu。pip show torch,确认Version字段显示为新版本;或在Python中执行import torch; print(torch.__version__),打印版本号验证。Ctrl + Alt + T启动终端。conda activate your_environment_name,切换至需要更新PyTorch的conda环境。conda update conda,确保conda为最新版本。conda list torch,查看当前安装的版本。conda remove pytorch torchvision torchaudio cudatoolkit,按提示确认卸载。conda update pytorch torchvision torchaudio -c pytorch。conda install pytorch torchvision torchaudio cudatoolkit=11.7 -c pytorch(需与显卡驱动支持的CUDA版本一致)。conda install pytorch torchvision torchaudio cpuonly -c pytorch。conda list torch,确认torch条目的版本号为最新;或在Python中执行import torch; print(torch.__version__)验证。nvidia-smi查看驱动版本,再对应CUDA Toolkit版本),确保PyTorch版本与CUDA版本兼容(如PyTorch 2.0+需CUDA 11.7及以上)。--force-reinstall强制重新安装,或手动卸载冲突的包)。