python安装torch-cluster、torch-scatter、torch-sparse和torch-geometric

跑图神经网络经常要安装torch-cluster、torch-scatter、torch-sparse和torch-geometric这些包,但是这些包安装挺麻烦的,经常因为版本不对应而报错,下面将介绍如何在版本对应的情况下安装这些包。

在import上面的包时,经常遇到的错误有以下两个:

错误 1:

RuntimeError: Detected that PyTorch and torch_scatter were compiled with different CUDA versions. PyTorch has CUDA version 10.2 and torch_scatter has CUDA version 11.3. Please reinstall the torch_scatter that matches your PyTorch install.

这个错误的意思就是说torch-cluster等包的cuda版本和torch的版本不对应,这个时候,首先先查一下当前环境下的cuda版本,看看是谁的问题:

(pytorch) name@aaaa:/data1/name/pytorch$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0

可以看到,明显是torch版本和cuda不对应,需要将torch的cuda版本换成11.3。

(pytorch) name@aaaa:/data1/name/pytorch$ pip uninstall torch

上torch网站下载轮子:https://download.pytorch.org/whl/torch_stable.html
在这里插入图片描述
找到需要下载的版本,右键,选择“复制链接地址”,wget去得到它的轮子:

(pytorch) name@aaaa:/data1/name/pytorch$ wget https://download.pytorch.org/whl/cu113/torch-1.10.1%2Bcu113-cp37-cp37m-linux_x86_64.whl

在当前目录下会得到torch-1.10.1+cu113-cp37-cp37m-linux_x86_64.whl的文件,然后利用pip install去安装即可。

(pytorch) name@aaaa:/data1/name/pytorch$ pip install torch-1.10.1+cu113-cp37-cp37m-linux_x86_64.whl

错误 2:

OSError: /home/name/anaconda3/envs/pytorch/lib/python3.7/site-packages/torch_sparse/_convert_cuda.so: undefined symbol: _ZNK2at6Tensor6deviceEv

本来以为上面错误1解决之后就可以正常import了,没想到报了错误2。这个错误不理解是什么意思,但我感觉还是包的版本没对应起来,虽然它们都已经是cuda11.3,但是可能包的内容还是没对应上,所以我决定将所有torch-cluster、torch-scatter、torch-sparse和torch-geometric这些包进行删除重装。

$ pip uninstall torch-cluster
$ pip uninstall torch-scatter
$ pip uninstall torch-sparse
$ pip uninstall torch-geometric

然后到这些包的所在网站下载轮子:https://pytorch-geometric.com/whl/
在这里插入图片描述
选择对应的torch和cuda版本,点击上面红框处,得到如下界面:
在这里插入图片描述
同样地,选择需要的版本,然后通过前面一样的步骤,wget和pip install安装这些包,就大功告成了。

  • 16
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值