Pytorch and Torchvision compiling with different versions of CUDA


I am installing ultralytics(YoloV8) on a new-ish computer with CUDA 12.1 installed. I was trying:

pip3 install torch torchvision torchaudio 

but when I run

from ultralytics import YOLO

I get:

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

I then tried:

pip3 install torch torchvision torchaudio --index-url

But got the same error. How can I resolve this?

Uninstall torch and torchvision until no proper installation can be found (you might have multiple installations in your current setup), then install both packages once, and post the install log here.