1. 安装
2022.8.3
我安装PyTorch用的Python3.8,命令是conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch
可以直接在DGL官网选择对应的情况,复制命令行进行安装:
注意在能够正常使用之前还需要安装psutil包,否则就会报如下错误:
Traceback (most recent call last): File "hello.py", line 1, in <module> import dgl.data File "my_env/envgraph1/lib/python3.8/site-packages/dgl/__init__.py", line 25, in <module> from . import dataloading File "my_env/lib/python3.8/site-packages/dgl/dataloading/__init__.py", line 10, in <module> from .dataloader import * File "my_env/lib/python3.8/site-packages/dgl/dataloading/dataloader.py", line 12, in <module> import psutil ModuleNotFoundError: No module named 'psutil'
安装psutil(psutil的官方下载教程网站:psutil/INSTALL.rst at master · giampaolo/psutil):
pip install psutil
2. 检验安装效果
import dgl.data dataset = dgl.data.CoraGraphDataset() print('Number of categories:', dataset.num_classes)
输出:
my_env/lib/python3.8/site-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.16.5 and <1.23.0 is required for this version of SciPy (detected version 1.23.1 warnings.warn(f"A NumPy version >={np_minversion} and <{np_maxversion}" Downloading user_path/.dgl/cora_v2.zip from https://data.dgl.ai/dataset/cora_v2.zip... Extracting file to user_path/.dgl/cora_v2 Finished data loading and preprocessing. NumNodes: 2708 NumEdges: 10556 NumFeats: 1433 NumClasses: 7 NumTrainingSamples: 140 NumValidationSamples: 500 NumTestSamples: 1000 Done saving data into cached files. Number of categories: 7
(这个SciPy和numpy的版本警告我也没辙)