python安装torch-cluster、torch-scatter、torch-sparse和torch-geometric | torch_geometric详细安装教程

1.检查CUDA版本

【方法1】用nvidia-smi

已装cuda,用nvidia-sminvcc -V 查看
在这里插入图片描述

【方法2】用torch

已装torch,用torch代码打印

import torch
print(torch.__version__)                # 查看pytorch安装的版本号
print(torch.cuda.is_available())        # 查看cuda是否可用。True为可用,即是gpu版本pytorch
print(torch.cuda.get_device_name(0))    # 返回GPU型号
print(torch.cuda.device_count())        # 返回可以用的cuda(GPU)数量,0代表一个
print(torch.version.cuda)               # 查看cuda的版本

在这里插入图片描述

2.安装torch(已装请跳过)

pip安装请看: https://download.pytorch.org/whl/torch_stable.html
找到自己系统环境+cuda版本+py版本 对应的torch轮子
我的是cu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl

  • 【安装方法】 下载安装(Linux可以用wget安装 / windows可以点击下载到本地)
    pip install whl的完整路径
pip install https://download.pytorch.org/whl/torch_stable.htmlcu117/torch-1.13.1%2Bcu117-cp310-cp310-linux_x86_64.whl

在这里插入图片描述

3.安装torch-geometric

去到网站:https://pytorch-geometric.com/whl/index.html
在这里插入图片描述

  • 【安装方法1】 :pip install -f 指定网址(带torch和cuda版本的网址)
    逐个包指定网址,也可以全部的包,一起指定网址
    pip install torch-scatter torch-sparse torch-spline-conv torch-cluster torch-geometric -f https://pytorch-geometric.com/whl/torch-1.13.1%2Bcu117.html
    
  • 【安装方法2】 :下载后,再逐个pip(按顺序)
    • torch_scatter
    pip install torch_scatter-2.1.0+pt113cu117-cp310-cp310-linux_x86_64.whl
    
    • torch_sparse
    pip install torch_sparse-0.6.17+pt113cu117-cp310-cp310-linux_x86_64.whl
    
    • 再到 torch_cluster
    pip install torch_cluster-1.6.1+pt113cu117-cp310-cp310-linux_x86_64.whl
    
    • 然后到 torch_cluster
    pip install torch_spline_conv-1.2.1+pt113cu117-cp310-cp310-linux_x86_64.whl
    
    • 最后到 torch_geometric(需关闭机场)
    pip install torch_geometric==2.0.4 -i https://pypi.doubanio.com/simple
    或者
    pip install torch_geometric -i https://mirrors.aliyun.com/pypi/simple
    或者
    pip install torch_geometric -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  • 检验是否安装成功
    • import torch_geometric 一下未报错即可
      在这里插入图片描述

4.常见错误

错误1. RuntimeError

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版本 + CUDA版本 + py版本,和 torch-geometric相关包的版本,是否一致。

.

错误2. An issue occurred xx

UserWarning: An issue occurred while importing ‘torch-scatter’. xxxxxxxx torch_scatter/_scatter_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl

UserWarning: An issue occurred while importing ‘torch-cluster’. xxxxxxxx
torch_cluster/_grid_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl

UserWarning: An issue occurred while importing 'torch-spline-conv’.
torch_spline_conv/_basis_cuda.so: undefined symbol: _ZNK3c107SymBool10guard_boolEPKcl

UserWarning: An issue occurred while importing ‘torch-sparse’.
torch_sparse/_diag_cuda.so: undefined symbol: _ZN3c106detail19maybe_wrap_dim_slowIlEET_S2_S2_b

  • 【解决方案】:卸载torch-geometric相关4个包,再按顺序 依次安装
    pip uninstall torch-cluster
    pip uninstall torch-scatter
    pip uninstall torch-sparse
    pip uninstall torch-geometric
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值