重点:1.一定要在创建虚拟环境的时候设置好python版本。2.一定要先确定使用1.X还是2.X的pyg库,二者不兼容。3.一定要将cuda、torch、pyg之间的版本对应好。所以,先确定pyg版本,再确定torch和cuda的版本。
结论:如果在ubuntu上安装python=3.7,torch=1.7.0,cuda=11.0,pyg=1.7.2,只用四行代码。
1)创建虚拟环境conda create -n <evn name> python==3.7
2)安装torch、torchvision、torchaudio、cudatoolkit
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0
3)安装scatter、sparse、cluster、spline_conv
pip install torch_scatter-2.0.5-cp37-cp37m-linux_x86_64.whl torch_sparse-0.6.8-cp37-cp37m-linux_x86_64.whl torch_cluster-1.5.8-cp37-cp37m-linux_x86_64.whl torch_spline_conv-1.2.0-cp37-cp37m-linux_x86_64.whl
4)安装pyg,如果要安装2.X版本的可以不加版本号
pip install torch-geometric==1.7.2
-----------------------------手动分割线,下面内容分析了怎么老是安装出错,下次再安装的时候来看看,内容有点乱----------------------------------
安装torch-geometric(pyg)的坑
踩坑一:无需自行安装CUDA,安装torch-gpu时,安装相应的cudatoolkit就可以了。所以nvcc -V
找不到cuda版本时没关系。
踩坑二:没有先确定pyg的版本。还有就是pip install torch-geometric的时候没有加上版本号。这两种情况都会报错 RuntimeError: The ‘data’ object was created by an older version of PyG. If this error occurred while loading an already existing dataset, remove the ‘processed/’ directory in the dataset’s root folder and try again.
原因是跑人家的代码中pyg版本与你安装的版本不