No module named torch_sparse, 及pytorch-geometric安装

pip安装完pytorch-geometric之后,报错No module named torch_sparse,搜了一下,居然是一个大坑,总结一下。网上各种方法都装不上,总是出各种问题,最后还是在官网上面找到安装方法。下面记载一下:

第一种方法(别人我不知道,我试着无效):

No module named torch_sparse, 及pytorch-geometric安装_第1张图片

 第二种方法(亲测有效):

We alternatively provide pip wheels for all major OS/PyTorch/CUDA combinations, see here

网址为:https://data.pyg.org/whl 链接过去后显示如图

No module named torch_sparse, 及pytorch-geometric安装_第2张图片

 然后根据pytorch和cuda版本选择所需要的whl文件,比如我的pytorch=1.9.0,cuda为10.2,所以我选择torch-1.9.0+cu102,链接过去得到下图,根据自己的python版本选择对应的whl文件就可以了,因为我的python版本是3.6的,所以选择了torch_cluster-1.5.9-cp36-cp36m-linux_x86_64.whl,torch_scatter-2.0.7-cp36-cp36m-linux_x86_64.whl   和 torch_sparse-0.6.10-cp36-cp36m-linux_x86_64.whlNo module named torch_sparse, 及pytorch-geometric安装_第3张图片

 注意:这几个whl文件可能也和顺序有关,要先安装torch_cluster和torch_scatter之后再安装torch_sparse,最后安装torch_geometric。

第三种方法(别人说可行,我测试着也不可行):

$ pip install torch-scatter==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-${TORCH}.html
$ pip install torch-sparse==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-${TORCH}.html
$ pip install torch-cluster==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-${TORCH}.html
$ pip install torch-spline-conv==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-${TORCH}.html
$ pip install torch-geometric
where${CUDA}and${TORCH}should be replaced by your specific CUDA version (cpu,cu92,cu101,cu102) and PyTorch version (1.4.0,1.5.0), respectively. For example, for PyTorch 1.5.0/1.5.1 and CUDA 10.2

根据个人电脑配置,选择相应的选项。

例如:

$ pip install torch-scatter==latest+cpu -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-sparse==latest+cpu -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-cluster==latest+cpu -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-spline-conv==latest+cpu -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-geometric

你可能感兴趣的:(python,深度学习,pytorch,深度学习,人工智能)