目录
1.通过Anaconda安装
2.通过pip安装
3.尝试历程:
参考
1.通过Anaconda安装
conda install pyg -c pyg -c conda-forge
2.通过pip安装
首先通过如下命令获取系统torch和CUDA版本:
python -c "import torch; print(torch.__version__)"
python -c "import torch; print(torch.version.cuda)"
然后再将得到的版本号填入下面的${}中
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-${TORCH}+${CUDA}.html
pip install torch-geometric
3.尝试历程:
conda install pyg -c pyg
发现啥也没安装上,报错如下:
ModuleNotFoundError: No module named 'torch_geometric'
conda install pyg -c pyg -c conda-forge
报错如下:
OSError: xxx/torch_sparse/_version_cpu.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKSs
检查安装的包,发现安装上了
torch的cou版本,还有下面的包:
而没有torch geometric
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.1+cu111.html
pip install torch-geometric
结果仍然报错:
torch_sparse/_version_cpu.so: undefined symbol: _ZN5torch3jit17parseSchemaOrNameERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
找到github上(https://github.com/pyg-team/pytorch_geometric/issues/999)说是由于torch和cuda安装版本和这个pyg矛盾导致的,所以可能需要重装torch和cuda,这又是一个浩大的工作量,折腾不动了,歇会儿
继续折腾,重新安装torch和cuda后,再用pip命令安装成功,(提醒:千万不要使用conda命令安装,多次尝试成功不了)
具体步骤:
1.安装torch和cuda(注意:这里最好安装整数版本,而不要小数版本,比如最好是1.9.0而不要装1.9.1):
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
注:装好了新torch后,我尝试用conda命令直接安装,结果仍然安装不上,最后还是尝试用pip
2.使用pip安装pyg
pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.9.0+cu111.html
pip install torch-geometric==2.0.3
注:安装完后torch sparse报了一个错,然后我就删除了 torch-sparse==0.6.15,装上了0.6.12
3.需要单独安装0.6.12。
pip install torch-sparse==0.6.12
成功!
总结:安装这些torch、cuda、pyg依赖的包版本有很强关联性,稍有不匹配可能就报错,最好用别人成功的镜像。
参考
在conda环境下安装PyTorch+PyTorch Geometric(Pyg)_Zayden4GNN的博客-CSDN博客_conda安装pyg
PyG(pytorch-geometric)安装 - 淼淼兮予怀 - 博客园 (cnblogs.com)