解决图神经网络库pytorch-geometric“版本不匹配”安装失败的问题

安装教程:

pytorch-geometric

1. 查看PyTorch版本(至少要1.4.0版本以上):

$ python -c "import torch; print(torch.__version__)"
>>> 1.8.0

2. 查看CUDA版本

$ python -c "import torch; print(torch.version.cuda)"
>>> 11.1

但是我利用上面这个代码查出来的CUDA版本却安装不了pytorch-geometric,或者是即使能够安装上,也不能调用该库,因此这里查出的CUDA版本并不正确。因此我查的网上说的是有两种查CUDA版本的方法,而且两种方法查出来的不一样,所以我就试了一下另一种方法:

$ nvcc --version

这时是显示我没有安装nvcc,因此就进入管理员账户,进行安装,安装命令如下:

sudo apt install nvidia-cuda-toolkit

3. 安装

安装好nvcc之后就可以通过上述“nvcc --version”查看CUDA版本了。查到版本号后,执行下列命令安装pytorch-geometric:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-geometric

其中第一个黄色部分(${TORCH})替换为PyTorch的版本号,第二个黄色部分(${CUDA})替换为上面查询得到的CUDA版本号。CUDA 版本号格式 (cpu, cu92, cu101, cu102, cu110, cu111)。例如对于PyTorch 1.8.0/1.8.1 and CUDA 11.1,安装命令如下:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+cu111.html
pip install torch-geometric

对于PyTorch 1.7.0/1.7.1 and CUDA 10.2,安装命令如下:

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.7.0+cu102.html
pip install torch-geometric

4. 检测是否安装成功

$ python
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torch_geometric.data import DataLoader
>>>

没有报错,说明安装成功。

5. 相关链接

为了安装pytorch-geometric,您可以按照以下步骤进行操作: 1. 访问PyTorch Geometric官网,网址为:https://pytorchgeometric.readthedocs.io/en/latest/notes/installation.html [1。 2. 根据您的PyTorch版本和CUDA版本,选择相应的命令进行安装。比如,如果您使用的是PyTorch 1.7.0和CUDA 11.0,可以使用以下命令进行安装: ``` pip install torch-scatter==latest cu110 -f https://pytorch-geometric.com/whl/torch-1.7.0.html pip install torch-sparse==latest cu110 -f https://pytorch-geometric.com/whl/torch-1.7.0.html pip install torch-cluster==latest cu110 -f https://pytorch-geometric.com/whl/torch-1.7.0.html pip install torch-spline-conv==latest cu110 -f https://pytorch-geometric.com/whl/torch-1.7.0.html pip install torch-geometric ``` [2] 3. 如果您使用的是PyTorch 1.6.0和CUDA 10.2,可以使用以下命令进行安装: ``` pip install torch-scatter==latest cu102 -f https://pytorch-geometric.com/whl/torch-1.6.0.html pip install torch-sparse==latest cu102 -f https://pytorch-geometric.com/whl/torch-1.6.0.html pip install torch-cluster==latest cu102 -f https://pytorch-geometric.com/whl/torch-1.6.0.html pip install torch-spline-conv==latest cu102 -f https://pytorch-geometric.com/whl/torch-1.6.0.html pip install torch-geometric ``` [3] 请根据您的PyTorch和CUDA版本选择适当的命令进行安装。希望对您有帮助!123 #### 引用[.reference_title] - *1* [PyTorch Geometric安装](https://blog.csdn.net/weixin_51736742/article/details/119379079)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] - *2* *3* [如何安装pytorch_geometric](https://blog.csdn.net/qq_28368377/article/details/109731397)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值