安装torch-geometric库


前言

记录下安装torch-geometric库出现的问题


一、查看cuda与torch版本

  • 使用以下命令查看cuda版本,这里我的版本是11.1
nvcc -V

在这里插入图片描述

  • 在创建的conda虚拟环境中,使用以下命令查看安装的torch版本,这里我的版本为1.9.1
conda list

在这里插入图片描述

二、提前安装其他依赖库

1、安装torch-scatter、torch-sparse、torch-cluster以及torch-spline-conv库

  • 访问以下网页https://data.pyg.org/whl/
  • 选择自己合适的版本,这里是我的版本
    在这里插入图片描述
  • 右键对应版本,选择复制链接
    在这里插入图片描述
  • 回到虚拟环境中执行以下命令
pip install torch_cluster -f https://data.pyg.org/whl/torch-1.9.0%2Bcu111/torch_cluster-1.5.9-cp38-cp38-linux_x86_64.whl

1.1、这时问题来了

  • 这是控制台输出内容:
WARNING: Skipping page https://data.pyg.org/whl/torch-1.9.0%2Bcu111/torch_cluster-1.5.9-cp38-cp38-linux_x86_64.whl because the HEAD request got Content-Type: binary/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting torch_cluster
  Using cached torch_cluster-1.6.3.tar.gz (54 kB)
  Preparing metadata (setup.py) ... done
  • 从警告信息和缓存行为来看,可能是由于 torch_cluster-1.6.3.tar.gz 的缓存导致安装失败,因为 pip 默认会优先使用本地缓存的包。为了避免使用缓存导致的问题,可以尝试清除 pip 缓存或者强制指定安装最新的可用版本
两种方式清除缓存
  1. 使用以下命令清除pip缓存
pip cache purge
  1. 强制忽略缓存
    使用 --no-cache-dir 参数强制忽略缓存
pip install --no-cache-dir
试了上述两种方式,仍然报错,以下是更多的报错信息
In file included from /usr/local/cuda-11.1/include/cuda_runtime.h:83,
                       from <command-line>:
      /usr/local/cuda-11.1/include/crt/host_config.h:139:2: error: #error -- unsupported GNU version! gcc versions later than 10 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
        139 | #error -- unsupported GNU version! gcc versions later than 10 are not supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this version check; however, using an unsupported host compiler may cause compilation failure or incorrect run time execution. Use at your own risk.
            |  ^~~~~
      error: command '/usr/local/cuda-11.1/bin/nvcc' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for torch_cluster
  Running setup.py clean for torch_cluster
Failed to build torch_cluster
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (torch_cluster)
  • 从错误信息来看,问题出在尝试使用较新版本的 GCC 编译 CUDA 代码时。CUDA 11.1 默认不支持 GCC 版本高于 10 的编译器,而你当前系统中使用的 GCC 可能是更新的版本

1.2、一种解决办法

预编译包下载出现问题:警告信息表明 pip 无法解析 .whl 文件的 MIME 类型,可能是 pip 版本过旧或 data.pyg.org 的兼容性问题

升级pip
pip install --upgrade pip
直接下载并安装.whl文件
  • 使用类似以下命令,将上述包对应.whl文件都下载到本地:
wget https://data.pyg.org/whl/torch-1.9.0%2Bcu111/torch_cluster-1.5.9-cp38-cp38-linux_x86_64.whl

在这里插入图片描述

  • 再安装
pip install torch_cluster-1.5.9-cp38-cp38-linux_x86_64.whl
安装成功

三、安装torch-geometric库

  • 安装链接:PyG

1、在右下角选择需要安装的版本

  • 这里我选择的是2.0.1版本
    在这里插入图片描述

2、选择安装

在这里插入图片描述

3、选好配置

在这里插入图片描述

这里我直接将这行命令输入到控制台中,问题又出现了

pip install torch-geometric -f https://data.pyg.org/whl/torch-1.9.0+cu111.html
  • 我期望安装的pyg版本为2.0.1版本,但强制安装成2.6.1
pip uninstall torch-geometric
  • 反复卸载重装后,问题仍未解决

分析原因

  • torch-geometric 的版本选择机制根据你当前环境中的 PyTorch 和依赖项的版本,认为 2.6.1 是兼容的最高版本

解决方式

  • 强制安装指定版本
pip install torch-geometric==2.0.1 -f https://data.pyg.org/whl/torch-1.9.0+cu111.html

四、至此,安装完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值