PyTorch torch_sparse installation without CUDA
Asked Answered
J

3

8

I am new in PyTorch and I have faced one issue, namely I cannot get my torch_sparse module properly installed. In general, I wanted to use module torch_geometric - this I have installed. However, when during the execution of the program I keep receiving the error ModuleNotFoundError: No module named ‘torch_sparse’ .

I try to intall it, but when I use the command pip install torch-sparse in anaconda, I get an error:

UserWarning: CUDA initialization:Found no NVIDIA driver on your system.

My system does not have a CUDA. So how could I install torch_sparse module without it?

Thank you in advance!

Kind regards

Rostyslav

Jasun answered 23/1, 2021 at 15:7 Comment(0)
F
13

As outlined in in pytorch_geometric installation instructions you have to install dependencies first and torch_geometric after that.

For PyTorch 1.7.0 and CPU:

pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+cpu.html
pip install --no-index torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+cpu.html
pip install --no-index torch-cluster -f https://pytorch-geometric.com/whl/torch-1.7.0+cpu.html
pip install --no-index torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.7.0+cpu.html
pip install torch-geometric

Please notice torch-1.7.0+cpu at the very end of each page

Fling answered 23/1, 2021 at 17:2 Comment(7)
Hi! Thank you for the reply! Well, I have uninstalled my ``` torch-geometric``` and now I am trying to install torch-scatter using pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.1.html However I receive an error ERROR: Could not find a version that satisfies the requirement torch-scatter (from versions: none) ERROR: No matching distribution found for torch-scatter even though my PyTorch version is 1.7.1 and I have no cuda. Do you know what is the reason?Jasun
@Jasun if you are using anaconda, please install pip inside conda first using conda install pip. After that follow with those commands.Fling
Sorry, I am using pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.1+cpu.html as you suggested. But still the same error ERROR: Could not find a version that satisfies the requirement torch-scatter (from versions: none) ERROR: No matching distribution found for torch-scatterJasun
@Jasun make sure that you use Python 3.8, not 3.9.Fling
I use Python 3.8.5Jasun
@Jasun pytorch-geometric.com/whl here are available versions. Go with torch-1.7.0 as in my answer, not in torch-1.7.1Fling
Works! Thank youJasun
C
0

I have found the use of conda instead of pip very useful. Running the following three commands turned out to be smooth and without errors:

  1. conda install -c pyg pytorch-sparse
  2. conda install -c pyg pytorch-scatter
  3. conda install -c pyg pyg

As far as I understood from the torch-geometric docs,we should be fine with these commands on CUDA/CPU.

Clementineclementis answered 14/3, 2023 at 13:50 Comment(0)
C
0

Updated Answer: I used this command and it worked like a charm!

!pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-2.3.0+cu121.html

Historical Answer:

I had the same problem with Google Colab. When I checked torch version using:

import torch
torch.__version__

I got 2.3.1+cu121. The latest version of torch-sparse (as of today!) works with torch-2.1.0. So I uninstalled the current torch, and installed the correct version:

!pip uninstall torch
!pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cu121

You might need to restart your session for the changes to affect. And after that as mentioned in previous answers:

!pip uninstall torch-scatter torch-sparse torch-geometric torch-cluster  --y
!pip install torch-scatter -f https://data.pyg.org/whl/torch-2.1.0+cu121.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-2.1.0+cu121.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-2.1.0+cu121.html
!pip install git+https://github.com/pyg-team/pytorch_geometric.git

It worked like a charm for me! I hope it helps you too! Just keep in mind that in the future torch-sparse might get updated to the latest torch version and you don't need to downgrade your torch version.

Connors answered 4/8 at 20:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.