16

I am trying to run the following on Google Colab : !pip install torch_sparse

At first, it seems to be working fine:

Collecting torch_sparse
  Downloading https://files.pythonhosted.org/packages/9a/86/699eb78ea7ce259da7f9953858ec2a064e4e5f5e6bf7de53aa6c8bb8b9a8/torch_sparse-0.6.9.tar.gz
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from torch_sparse) (1.4.1)
Requirement already satisfied: numpy>=1.13.3 in /usr/local/lib/python3.7/dist-packages (from scipy->torch_sparse) (1.19.5)
Building wheels for collected packages: torch-sparse

But from here it just keeps running forever, without outputting any error message, and the wheels never get built.

My Colab environment is hosted and uses a GPU accelerator. I can also install torch and initialize cuda beforehand, but it doesn't change anything.

10 Rep
  • 2,217
  • 7
  • 19
  • 33
Anthony Frion
  • 281
  • 1
  • 2
  • 6

6 Answers6

13

Putting together all the previous answers, here is the snippet that should work whatever runtime of colabs

import torch

!pip uninstall torch-scatter torch-sparse torch-geometric torch-cluster  --y
!pip install torch-scatter -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{torch.__version__}.html
!pip install git+https://github.com/pyg-team/pytorch_geometric.git
Nodiz
  • 333
  • 2
  • 8
12

The installation actually got completed after 30 minutes to 1 hour (I don't have the exact timing). However, when trying to import torch_sparse I had the issue described here : PyTorch Geometric CUDA installation issues on Google Colab

I tried applying the most popular answer, but since it seems to be obsolete I updated it to the following :

!pip install torch-geometric \
  torch-sparse \
  torch-scatter \
  torch-cluster \
  -f https://pytorch-geometric.com/whl/torch-1.8.0+cu101.html

This installation worked just fine and took only a few seconds. So far, it looks like it makes me able to import everything I need from torch_geometric/torch_sparse. I'll tell you if I experience any issue with this later !

Anthony Frion
  • 281
  • 1
  • 2
  • 6
3

To ease portability, it is also possible to automatically provide the path to the appropriate url given the available pytorch version:

import torch
print(torch.__version__)
!pip install torch-scatter torch-sparse -f https://data.pyg.org/whl/torch-{torch.__version__}.html
Tom
  • 61
  • 7
1

To add on to the previous answer, Matthias Fey suggested the following approach for downloading the dependencies in colab :

!pip install -q torch-scatter -f https://data.pyg.org/whl/torch-1.9.0+cu111.html
!pip install -q torch-sparse -f https://data.pyg.org/whl/torch-1.9.0+cu111.html
!pip install -q git+https://github.com/pyg-team/pytorch_geometric.git

This Colab link and Github link may help.

1

None of the above answers worked for me. The wheels on the build went round and round, round and round. I have written below what worked as of posting date:

  1. First find your torch version:

    import torch print(torch.__version__)

1.10.0+cu111

  1. If you're like me and your colab's cuda is not listed in pytorch-geometric's installation directions, then drawing from the installation method of their tutorial notebooks, use the following:
!pip uninstall torch-scatter torch-sparse torch-geometric torch-cluster  
!pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-1.10.0+cu111.html
!pip install git+https://github.com/pyg-team/pytorch_geometric.git

Note: You can use https://data.pyg.org/whl/torch-{torch.__version__}.html to replace above

import torch

!echo https://data.pyg.org/whl/torch-{torch.__version__}.html 

https://data.pyg.org/whl/torch-{1.10.0+cu111}.html

vinceW
  • 11
  • 3
0

In my environment, I had pytorch 2.0.1 with cuda 11.8 on windows.

At PyG installation guide: https://pytorch-geometric.readthedocs.io/en/latest/install/installation.html, I provided my system specification and got the command:

pip install torch_scatter torch_sparse torch_cluster torch_spline_conv -f https://data.pyg.org/whl/torch-2.0.0+cu118.html

This worked just fine

Harsh
  • 1