PyTorch,torchvision版本对应关系
概述
PyTorch 和 torchvision 之间存在版本依赖关系。选择兼容的版本组合对于项目的稳定性至关重要。
版本对应表
| PyTorch | torchvision | Python |
|---|
| 2.9.x | 0.24.x | 3.10-3.14 |
| 2.8.x | 0.23.x | 3.9-3.13 |
| 2.7.x | 0.22.x | 3.9-3.13 |
| 2.6.x | 0.21.x | 3.8-3.12 |
| 2.5.x | 0.20.x | 3.8-3.12 |
| 2.4.x | 0.19.x | 3.8-3.12 |
| 2.3.x | 0.18.x | 3.8-3.12 |
| 2.2.x | 0.17.x | 3.8-3.12 |
| 2.1.x | 0.16.x | 3.8-3.11 |
| 2.0.x | 0.15.x | 3.8-3.11 |
| 1.13.x | 0.14.x | 3.7-3.11 |
| 1.12.x | 0.13.x | 3.7-3.10 |
| 1.11.x | 0.12.x | 3.7-3.10 |
| 1.10.x | 0.11.x | 3.6-3.10 |
| 1.9.x | 0.10.x | 3.6-3.10 |
安装建议
使用 pip 安装
cpu版本安装
1
| pip install torch==2.5.0 torchvision==0.20.0
|
gpu版本安装 可根据需求更改版本
1
| pip3 install torch==2.5.0+cu118 torchvision==0.20.0+cu118 --index-url https://download.pytorch.org/whl/cu118
|
验证安装
1
| python -c "import torch; import torchvision; print(f'PyTorch: {torch.__version__}'); print(f'torchvision: {torchvision.__version__}')"
|
测试gpu是否可用
1
2
| import torch
torch.cuda.is_available()
|
官方资源