基于Pytorch运行中出现RuntimeError: Not compiled with CUDA support此类错误解决方案及基于Pytorch中安装torch_geometric可以命令模式安装方法

注意:每个python虚拟环境都是可以安装此环境独自需要的cuda版本等。

一、首先在python程序运行的过程中出现了“RuntimeError: Not compiled with CUDA support”错误。

二、然后经过博主不断尝试网上各种解决方案都没有解决,然后发觉可能是之前安装的torch_scatter文件出现了问题(之前安装参考文章和方式如下,也就是直接下载torch_scatter对应版本的whl文件然后安装)。

pip install torch_scatter-2.0.9-cp37-cp37m-win_amd64.whl

参考安装文章:点击打开《基于Pytorch中安装torch_geometric简单详细完整版》文章

三、然后博主决定重新更换torch_scatter版本,但是出现“OSError: /usr/local/cuda-10.2/lib64/libcudart.so.10.1: version `libcudart.so.10.1’ not found (required by /home/xieru21/anaconda3/envs/hiv/lib/python3.7/site-packages/torch_scatter/_scatter_cuda.so)”错误,说明更换torch_scatter版本是有问题的。然后博主又重新和之前安装方式一样重新用whl文件安装torch_scatter,但是还是出现“RuntimeError: Not compiled with CUDA support”错误。

四、然后本人决定更换安装方式,采用命令形式不用whl文件安装,注意:博主之前在此python虚拟环境安装的就是cuda10.2和pytorch1.10,所以下面的命令中采用这个torch-1.10.0+cu102,否则需要更改,链接前面的内容可以不更改只需要更改“torch-1.10.0+cu102”此部分,怎么更改除参考自己虚拟环境的cuda和pytorch版本,还需要点击此链接核对一下对应的cuda和pytorch版本。比如:你的虚拟环境pytorch版本是1.11.0,cuda版本是11.3那么命令中的链接https://data.pyg.org/whl/torch-1.10.0+cu102.html改成https://data.pyg.org/whl/torch-1.11.0+cu113.html,其他照旧。安装完成之后发现torch_scatter版本还是之前安装的版本,说明之前安装的方式还是有些bug存在。

pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

y


五(可跳)、鉴于之前的安装方式有bug存在,那么基于Pytorch中安装torch_geometric可以换成新的命令模式安装,这个安装方式是和此篇《基于Pytorch中安装torch_geometric简单详细完整版》文章对比。博主举例的依旧是cuda版本是10.2,然后pytorch版本是1.10。

  • 创建一个叫做test的python=3.7的虚拟环境
conda create -n test python=3.7

y

  • 激活test虚拟环境
conda activate test

  • 安装cuda10.2(注意:如果conda版本等级太低无法用conda命令安装cuda高级版本的,比如cuda11.3.1,所以需要先升级conda版本,命令是:conda update -n base -c defaults conda
conda install cudatoolkit==10.2.89

y

pip install torch-1.10.0+cu102-cp37-cp37m-linux_x86_64.whl

  • 下载配置torch-geometric,注意:torch_sparse的安装还是要指定其安装版本,否则会报错安装失败,但是torch-geometric可以不指定安装版本,但是根据需求可以指定。
pip install torch-scatter -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

pip install torch_sparse==0.6.13 -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

pip install torch_cluster -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

pip install torch_spline_conv -f https://data.pyg.org/whl/torch-1.10.0+cu102.html

pip install torch-geometric==2.0.1

  • 测试torch_geometric安装是否成功,复制下面命令运行没有报错就说明安装成功。
python

import torch_geometric