Bootstrap

torch_geometric安装避坑

总流程:

1. 查看cuda, pytorch, python版本;

2. 依次安装torch_scatter, torch_sparse, torch_cluster, torch_spline;

3. 安装torch_geometric

一. 查看cuda, pytorch, python版本

可选方法如下图,其中该样例的cuda, pytorch, python版本分别为10.2, 1.10.0, 3.7

二. 依次安装torch_scatter, torch_sparse, torch_cluster, torch_spline

1. 常见报错

(1)错误类型1

指令:pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.10.0+cu102.html

即使按步骤一的结果指定了torch_scatter的版本,但还出现以下报错:

Failed to build torch-scatter
Installing collected packages: torch-scatter
    Running setup.py install for torch-scatter ... error
    ERROR: Command errored out with exit status 1:

(2)错误类型2

指令:pip install torch-cluster==latest+cu102 -f https://pytorch-geometric/com/whl/torch-1.10.0.html

但报错:找不到指定类型的版本ERROR: Could not find a version that satisfies the requirement torch-cluster==latest+cu102

 (3)错误类型3

安装没有错,但import torch-cluster时出现OSError: [WinError 127] 找不到指定的程序。:

 2. 正确安装

Step 1: 将torch_scatter, torch_sparse, torch_cluster, torch_spline的对应版本下载到本地,然后进行安装。

下载地址:https://pytorch-geometric.com/whl/

在以下页面根据对应的torch和cuda版本点击进入,

 根据对应的系统类型(linux or windows)和python版本选择torch_scatter, torch_sparse, torch_cluster, torch_spline下载。

 Step 2: cd到下载后的文件路径,pip install安装对应的4个包。下图以torch_cluster为例:

 Step 3: 验证是否安装成功。

下图以torch_cluster为例,import torch_cluster没有报错,则安装成功。

 三. 安装torch_geometric

此时,pip install torch_geometric,安装完成。

But 如果在import torch_geometric时,还出现TypeError: Expected ‘Iterator’ as the return annotation for __iter__ of SMILESParser, but found typing.Any的错误,这是因为pip install torch_geometric自动安装的版本不对,处理方法如下:

pip uninstall torch_geometric

pip install torch_geometric=2.0

;