报错Detected that PyTorch and torchvision were compiled with different CUDA major versions. PyTorch ha

完整报错:

Detected that PyTorch and torchvision were compiled with different CUDA major versions. PyTorch has CUDA Version=12.1 and torchvision has CUDA Version=11.8. Please reinstall the torchvision that matches your PyTorch install.

检查

import torch
print(f"PyTorch 版本: {torch.__version__}")  
print(f"PyTorch 编译时使用的 CUDA 版本: {torch.version.cuda}")  
print(f"PyTorch 当前可用的 CUDA: {torch.cuda.is_available()}")  
print(f"CUDA 设备版本: {torch.cuda.get_device_capability()}")  

输出:

PyTorch 版本: 2.1.0+cu121
PyTorch 编译时使用的 CUDA 版本: 12.1
PyTorch 当前可用的 CUDA: True
CUDA 设备版本: (8, 6)

解决:重新安装同一版本全家桶

# 1. 卸载现有版本
pip uninstall torch torchvision torchaudio -y

# 2. 安装 CUDA 11.8 的 PyTorch 全家桶
pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu118

 

你可能感兴趣的:(学习记录,人工智能)