PyTorch and torch_sparse were compiled with different CUDA versions

Hi. I want to run a python program but there is an error in pytorch:

RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 10.2 and torch_sparse has CUDA version 11.4. Please reinstall the torch_sparse that matches your PyTorch install.

How to fix it?

From torch-sparse documentation, It seems there is an option to install the library for specific version of CUDA. Did you try that?

For example, if you have torch 1.11, you could try:

pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-1.11.0+cu102.html

I tested it but it doesn’t work

Can you try a clean install or try to uninstall and then install?
I am able to follow the procedure and install it for CUDA 11.3 & Pytorch 1.11.

Also, In this case, it will be great if you could mention some more details such as the error message, the pytorch version, and how did you install torch (source / conda/ pip ) to know more context?