torch环境

image-20231219122612389

1.安装对应的torch、torchvision

网址:https://pytorch.org/get-started/previous-versions/

搜索对应CUDA版本的安装命令(cu110代表CUDA11.0),在终端中复制命令安装。

image-20231219113547226

查看是否安装成功

1
2
3
import torch
print(torch.__version__)
print(torch.version.cuda)

2.安装torch-geometric

网址:https://pytorch-geometric.com/whl/

找到对应pytorch版本:

image-20231219113754141

四个库(cluster,scatter,sparse,spline-conv)分别:wget 网页中对应的链接并 pip install 下载好的whl包,即完成安装:

image-20231219113927345

注意自己环境的python版本以及linux/win就行

安装完上面四个库后执行 pip install torch-geometric

以上安装完成。

完成之后 import torch-geometric 发现报错,报错信息:“No module named 'torch.profiler”

原因是torch1.10以上的版本才有torch.profiler这个库,但是Torch网址CUDA11.0兼容的选项没有torch1.10以上,那怎么办呢?

解决:

找到报错路径里的文件profile.py

作如下修改:(原文件是第八行,改成了第九行)

image-20231219114012578

3 DGL安装

安装DGL无需安装torch-geometric,需要安装那四个依赖库

Deep Graph Library (dgl.ai)

1
2
3
4
5
6
7
8
9
conda create -n mVul python=3.7

pip install torch==1.5.0+cu102 torchvision==0.6.0+cu102 torchaudio==0.5.0 -f https://download.pytorch.org/whl/cu102/torch_stable.html

torch 1.5.0
torchgeometric
pip install networkx==2.5
pip install dgl -f https://data.dgl.ai/wheels/cu102/repo.html
https://data.dgl.ai/wheels/cu113/repo.html