Article directory
1. Problem description
Although you can directly use pip to download and install, but Kaggle's BUG causes some libraries to be slow to install online.
Taking PyG as an example, online installation often requires 30-60分钟
left and right, but if you upload the required wheel file to Kaggle and use local installation, the 1分钟
installation can be completed.
2. Resolution steps
2.1 Uninstall the default environment
First of all, pyg has requirements for torch and cuda versions, but the default environment of kaggle does not support pyg, so first uninstall the torch that comes with kaggle
pip uninstall torch torchvision torchaudio --y
2.2 Install the appropriate version
Install torch, the recommended version is 1.12.1-cu113
pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113
2.3 Install PyG
install pyg
For the first time, turn on the GPU acceleration of kaggle, and then run
pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv torch_geometric -f https://data.pyg.org/whl/torch-1.12.0+cu113.html
After waiting for a long time, it shows that the installation is successful
Test it, the output Data(edge_index=[2, 4], x=[3, 1])
is that the installation is successful
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index)
print(data)
2.4 Extract the installation cache wheel file
Create save directory
import os
os.mkdir('files')
Copy the file to the output folder, then you can download it in output
!cp -r ~/.cache/pip/wheels/*/*/*/*/*.whl /kaggle/working
After the download is complete, put these whl files into a folder, and then download the following two whl files (click to download)
Compress all 6 whl files downloaded above into a compressed package, create a dataset in kaggle, and upload the compressed package
Just add the compressed package to the notebook that needs to use pyg
2.5 Install the whl file in the compressed package
!pip install pyg_lib torch_scatter torch_sparse torch_cluster torch_spline_conv torch_geometric --no-index --find-links=file:///kaggle/input/pyg-packages-torch1121-cu113/pyg-packages
You can also use my dataset directly, the name ispyg-packages-torch1.12.1+cu113