最近在准备GCN运行环境,需要安装PyG库,遇到了很多问题,一一解决形成了本篇博客。本文采用的是离线安装。需要在本地下载whl文件。
1.
在安装前要检查电脑的上的python、torch和cuda版本
import torch
print(torch.__version__)
#检查torch版本;
import torch
print(torch.version.cuda)
#检查cuda版本;
以我的为例:
2.在官网找到对应的版本,进行下载。(data.pyg.org/whl/)
我的torch版本是1.12.0+cu113,看自己的版本是哪一个就下载哪一个,也有CPU版本。
需要下载的文件有4个,分别是1.torch-scatter 2.torch-sparse 3.torch-cluster 4.torch-spline-conv
下载到一个自己能找到的位置。
依次安装这四个文件。需要注意的是,我需要把文件安装在已经有的torch环境中,就需要从anaconda进入文件路径进行安装。指令是 pip install + 包名,这里举例,我的版本已经知道torch=1.12.0,cuda=113。
pip install torch_scatter-2.1.0+pt112cu113-cp39-cp39-win_amd64.whl
pip install torch_sparse-0.6.15+pt112cu113-cp39-cp39-win_amd64.whl
install torch_cluster-1.6.0+pt112cu113-cp39-cp39-win_amd64.whl
pip install torch_spline_conv-1.2.1+pt112cu113-cp39-cp39-win_amd64.whl
#pip install + 包名
下面是一个样例:
3.下载安装完这四个文件以后还需要做一件事情,利用镜像源下载一个安装包:
pip install -U -i https://pypi.tuna.tsinghua.edu.cn/simple torch_geometric
4.做完这些以后PyG就安装完毕了。不过我在打开JupyterNotebook还遇到了一个报错,TqdmWarning: IProgress not found. Please update jupyter and ipywidgets.
这个问题很容易解决,只需要根据提示更新
pip install ipywidgets
5.最后打开JupyterNotebook导入需要的包,没有前面的报错,安装完毕。
import torch
from torch_geometric.nn import MessagePassing
from torch_geometric.utils import add_self_loops, degree