Skip to content

Instantly share code, notes, and snippets.

@ameya98
Last active September 28, 2024 03:49
Show Gist options
  • 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
@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.

@MarkValadez
Copy link

Same here, worked well for me!

@benisalla
Copy link

this worked for me in colab notebook:

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

but make sure that you have the same torch version as here: 2.4.0 ( because i have torch-2.4.0)

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