Installing PyTorch Geometric Toolkit

Installing PyTorch Geometric Toolkit
Installing PyTorch Geometric Toolkit
Click the blue text above to follow us!
Installing PyTorch Geometric Toolkit

To learn GNN, you will definitely use the torch_geometric package. PyG (PyTorch Geometric) is a library built on PyTorch that allows easy writing and training of Graph Neural Networks (GNNs), suitable for various applications related to structured data. A GCNConv can be easily called with just one line of code. Below is a detailed introduction to the installation process of the torch_geometric package.

1Environment Version Check

To prevent various package version matching issues later, it is advisable to create a new virtual environment. If you have already created a virtual environment, ensure that we can properly call this package within the virtual environment. The following checks are needed for the Python version, PyTorch version, and whether the GPU and CUDA version can be correctly called. The command is as follows:
[Enter Virtual Environment]
Open Anaconda Prompt and enter the following command to enter the virtual environment
conda activate your-evn-name
Enter the following commands one by one:
import torch
print(torch.__version__)                # Check the installed version of PyTorch
print(torch.cuda.is_available())        # Check if CUDA is available. True means available, indicating GPU version of PyTorch
print(torch.cuda.get_device_name(0))    # Return GPU model
print(torch.cuda.device_count())        # Return the number of available CUDA (GPU), 0 means one
print(torch.version.cuda)               # Check CUDA version
The results are as follows:
Installing PyTorch Geometric Toolkit
If the virtual environment has not installed the torch library, refer toPython tutorial | Configure CUDA (Nanny Tutorial)for the correct installation of the torch library.

🔔Note: To install torch, you need to go to the GitHub page of the pyg-team to find pytorch-geometric. The website is https://github.com/pyg-team/pytorch_geometric. Then click on the location below to jump to the link.

Installing PyTorch Geometric Toolkit

After that, a new interface will pop up, as shown. Find the appropriate torch version according to your computer situation, and select the corresponding CUDA version. For me, it is the gray torch-1.8.0+cu111 selected in the image (the image is only for illustration; the actual choice is torch-1.8.0+cu111). Here is the direct URL: https://data.pyg.org/whl/

Installing PyTorch Geometric Toolkit

2Install Dependencies

As shown in the image above, there are a total of four dependencies: torch_scatter, torch_sparse, torch_cluster, and torch_spline_conv. You only need to download one of each (torch_scatter-1.5.8 indicates the version number of torch_scatter, cp39 indicates Python 3.9, win indicates Windows operating system, choose according to your computer’s actual conditions). Clicking will download the whl type file. Below are the downloaded files:
Installing PyTorch Geometric Toolkit
Enter the virtual environment and use pip to install (be sure to use pip for installation, conda installation may sometimes encounter issues). Below are the commands to run:
pip install C:\Users\dell\Downloads\torch_cluster-1.5.9-cp39-cp39-win_amd64.whl
pip install C:\Users\dell\Downloads\torch_spline_conv-1.2.1-cp39-cp39-win_amd64.whl
pip install C:\Users\dell\Downloads\torch_sparse-0.6.12-cp39-cp39-win_amd64.whl
pip install C:\Users\dell\Downloads\torch_scatter-2.0.8-cp39-cp39-win_amd64.whl
Installing PyTorch Geometric Toolkit
After installing the four dependencies, you can install the torch-geometric package.
pip install torch-geometric==2.0.4
You need to find the version of torch-geometric that matches torch.

3Run Test

Enter the following code in Python, and if it runs normally, everything is ready.
Installing PyTorch Geometric Toolkit
That’s ALL FOR TODAY
Supplementary Note

After installation, the default matching numpy package is version 2.0.2, which may not match torch=1.8.0 in some cases, leading to code errors and inability to run correctly. It needs to be uninstalled and reinstalled with the corresponding version. I chose numpy=1.23.5 version;

In some cases, it may lead to GitHub being inaccessible. The dependency files and datasets used in the example can be obtained by replying: PyG Demo in the background! If you encounter problems, feel free to discuss in the comments section~

Installing PyTorch Geometric Toolkit
—END—

â–²

Follow our public account for more related materials!

Leave a Comment