Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ameya98
Last active April 13, 2024 09:15
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ameya98/b193856171d11d37ada46458f60e73e7 to your computer and use it in GitHub Desktop.
Save ameya98/b193856171d11d37ada46458f60e73e7 to your computer and use it in GitHub Desktop.
Google Colab: PyTorch Geometric Installation
# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch
def format_pytorch_version(version):
return version.split('+')[0]
TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)
def format_cuda_version(version):
return 'cu' + version.replace('.', '')
CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)
!pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric
@ameya98
Copy link
Author

ameya98 commented Oct 4, 2020

Ah, I expected this to happen eventually. This script is quite rudimentary. Can you please print out the variables TORCH_version and CUDA_version in the script above?

@ameya98
Copy link
Author

ameya98 commented Oct 4, 2020

I just tested this on the CPU, GPU and TPU runtimes on Colab, and I can successfully import PyG.

@msaroufim
Copy link

This worked for me - thank you!

@17barbieri
Copy link

Hi,
For some reason this code worked perfectly well once and dosn't work any more now.
Do you know about any changes in Colab/PyTorch between the 26 ad 27 February ?
I get the following error:

Looking in links: https://pytorch-geometric.com/whl/torch-1.7.1.html
ERROR: Could not find a version that satisfies the requirement torch-scatter==latest+cu101 (from versions: 0.3.0, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.3.0, 1.3.1, 1.3.2, 1.4.0, 2.0.2, 2.0.3, 2.0.4, 2.0.5)
ERROR: No matching distribution found for torch-scatter==latest+cu101

Looking in links: https://pytorch-geometric.com/whl/torch-1.7.1.html
ERROR: Could not find a version that satisfies the requirement torch-sparse==latest+cu101 (from versions: 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.5.1, 0.6.0, 0.6.1, 0.6.3, 0.6.4, 0.6.5, 0.6.6, 0.6.7, 0.6.8)
ERROR: No matching distribution found for torch-sparse==latest+cu101

Looking in links: https://pytorch-geometric.com/whl/torch-1.7.1.html
ERROR: Could not find a version that satisfies the requirement torch-cluster==latest+cu101 (from versions: 0.1.1, 0.2.3, 0.2.4, 1.0.1, 1.0.3, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.4.3a1, 1.4.3, 1.4.4, 1.4.5, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8)
ERROR: No matching distribution found for torch-cluster==latest+cu101

Looking in links: https://pytorch-geometric.com/whl/torch-1.7.1.html
ERROR: Could not find a version that satisfies the requirement torch-spline-conv==latest+cu101 (from versions: 0.1.0, 1.0.0, 1.0.1, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.1.0, 1.1.1, 1.2.0, 1.2.1)
ERROR: No matching distribution found for torch-spline-conv==latest+cu101

I'm using python 3.7.1, cuda version is 1.0.1 and I'm using colab's GPUs...
Thanks in advance for your help !

@ameya98
Copy link
Author

ameya98 commented Feb 27, 2021

I believe this is due to upstream changes in pip v20.3 and later. I had similar issues elsewhere.

Edit: Should be fixed now! I used the solution at pyg-team/pytorch_geometric#1876.
Let me know if it works!

@nshl99
Copy link

nshl99 commented Mar 2, 2021

Hi, I've just tried this, but I'm still getting this same error:

RuntimeError: Detected that PyTorch and torch_scatter were compiled with different CUDA versions. PyTorch has CUDA version 10.1 and torch_scatter has CUDA version 0.0. Please reinstall the torch_scatter that matches your PyTorch install.

It's strange as I managed to get it to work this morning without using this method, but that doesn't work too now.
Any ideas?

I ran it again but this time on the GPU, and I now get this error when trying to import torch_geometric:
RuntimeError: Detected that PyTorch and torch_sparse were compiled with different CUDA versions. PyTorch has CUDA version 10.1 and torch_sparse has CUDA version 11.0. Please reinstall the torch_sparse that matches your PyTorch install.

I installed torch again with:
!pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

Then proceeded to install all the torch_geometric modules using torch1.7.1+cu110, and this seems to work fine

@ameya98
Copy link
Author

ameya98 commented Mar 3, 2021

Interesting, I'll take a look.

@17barbieri
Copy link

I believe this is due to upstream changes in pip v20.3 and later. I had similar issues elsewhere.

Edit: Should be fixed now! I used the solution at rusty1s/pytorch_geometric#1876.
Let me know if it works!

Works thank you very much !

@m-e-l-u-h-a-n
Copy link

Huge thanks for this works for me without any changes needed.

@ali1810
Copy link

ali1810 commented Jun 3, 2021

!pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html

This works for me as I was having problem to solve the problem installing torch-scatter

@ameya98
Copy link
Author

ameya98 commented Jun 3, 2021

Not sure I understand, is something not working? @ali1810

@usualwitch
Copy link

Thank you! Works perfectly!

@homerjed
Copy link

homerjed commented Jul 7, 2021

I found only this worked, and it worked in under 5x the time:

!pip install -q torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-geometric

@siddarth-c
Copy link

I found only this worked, and it worked in under 5x the time:

!pip install -q torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
!pip install -q torch-geometric

@homerjed Works well:+1:

@ameya98
Copy link
Author

ameya98 commented Jul 11, 2021

Thanks @homerjed! Let me try to see if there's a way that will automatically find the latest package versions.

@vgthengane
Copy link

It worked for me. Thank you

@mmcinnestaylor
Copy link

This was massively helpful. Thanks!

@Jiayi-Pan
Copy link

Jiayi-Pan commented Nov 3, 2021

Colab has updated its cuda version recently, and ALL the solutions above seem DO NOT WORK.
TRY THIS ONE

# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch

def format_pytorch_version(version):
  return version.split('+')[0]

TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
  return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric

@IbtihalFerwana
Copy link

That also did not work with me,
I received this error OSError: libcudart.so.10.2: cannot open shared object file: No such file or directory

@ved164
Copy link

ved164 commented Feb 1, 2022

Works for me. Thank you.

@kunal-bhadra
Copy link

@Jiayi-Pan's code still works today. Thanks!

@shahriar1489
Copy link

Code works fine. Thank you!

@paulagd
Copy link

paulagd commented May 3, 2022

This was very helpful! Still works today!

@talha1503
Copy link

Colab has updated its cuda version recently, and ALL the solutions above seem DO NOT WORK. TRY THIS ONE

# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch

def format_pytorch_version(version):
  return version.split('+')[0]

TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
  return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric

This is not working currently on google colab. Can anyone help me out? Thanks in advance.

@Jiayi-Pan
Copy link

Jiayi-Pan commented May 14, 2022

Add this in a Google Colab cell to install the correct version of Pytorch Geometric.

import torch

def format_pytorch_version(version):
return version.split('+')[0]

TORCH_version = torch.version
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric

Hi, it still works fine on my side at Colab as 2022/5/14.

@yezil3
Copy link

yezil3 commented Jul 20, 2022

Colab has updated its cuda version recently, and ALL the solutions above seem DO NOT WORK. TRY THIS ONE

# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch

def format_pytorch_version(version):
  return version.split('+')[0]

TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
  return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric

Works! Thanks a lot!

@suraniadi
Copy link

Works. Cool!

@mathsrocks
Copy link

Colab has updated its cuda version recently, and ALL the solutions above seem DO NOT WORK. TRY THIS ONE

# Add this in a Google Colab cell to install the correct version of Pytorch Geometric.
import torch

def format_pytorch_version(version):
  return version.split('+')[0]

TORCH_version = torch.__version__
TORCH = format_pytorch_version(TORCH_version)

def format_cuda_version(version):
  return 'cu' + version.replace('.', '')

CUDA_version = torch.version.cuda
CUDA = format_cuda_version(CUDA_version)

!pip install torch-scatter -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-sparse -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-cluster -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-spline-conv -f https://data.pyg.org/whl/torch-{TORCH}+{CUDA}.html
!pip install torch-geometric

Works like a charm, thanks - installation time down from 33min to 36sec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment