ubuntu安装pytorch-geometric
1.environment
OS:ubuntu20.04
Python version:Python 3.6.8
PyTorch version:1.4.0
CUDA/cuDNN version:10.1
2.安装流程
(1)检查pytorch支持cuda
$ python -c "import torch; print(torch.cuda.is_available())"
>>> True
(2)添加路径
$ export PATH=/usr/local/cuda/bin:$PATH
$ echo $PATH
>>> /usr/local/cuda/bin:...
$ export CPATH=/usr/local/cuda/include:$CPATH
$ echo $CPATH
>>> /usr/local/cuda/include:...
$ export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
$ echo $LD_LIBRARY_PATH
>>> /usr/local/cuda/lib64:...
$ export DYLD_LIBRARY_PATH=/usr/local/cuda/lib:$DYLD_LIBRARY_PATH
$ echo $DYLD_LIBRARY_PATH
>>> /usr/local/cuda/lib:...
(3)确认PyTorch与系统 CUDA 版本匹配
$ python -c "import torch; print(torch.version.cuda)"
10.1
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Fri_Feb__8_19:08:17_PST_2019
Cuda compilation tools, release 10.1, V10.1.105
(4)pip安装依赖
版本库: https://pytorch-geometric.com/whl/torch-1.4.0.html.
一般情况:
$ pip install torch-scatter==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-sparse==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-cluster==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ pip install torch-spline-conv==latest+${CUDA} -f https://pytorch-geometric.com/whl/torch-1.5.0.html
$ python setup.py install or pip install torch-geometric
注意要把${CUDA} 替换成cu100或者cu101或者你的版本,+号和latest都不要变,但是我的一直提示版本问题,提示找不到版本软链接,于是我尝试了以下方法,成功!
cu101代表cuda10.1,cp36代表python3.6版本,linux系统,下载这个到本地,然后copy到服务器上所在文件夹。
下载对应的whl文件后,在终端进入whl所在的文件夹,输入pip install xxx.whl进行安装就可以了。whl大法真的好!!!
$ pip install torch_sparse-0.5.1+cu101-cp36-cp36m-linux_x86_64.whl
......
$ pip install torch_scatter-2.0.3+cu101-cp36-cp36m-linux_x86_64.whl
Processing ./torch_scatter-2.0.3+cu101-cp36-cp36m-linux_x86_64.whl
Installing collected packages: torch-scatter
Successfully installed torch-scatter-2.0.3
$ pip install --verbose --no-cache-dir torch-cluster
$ pip install --verbose --no-cache-dir torch-spline-conv (optional)
$ pip install torch-geometric
在pip第四句时,出现bash: syntax error near unexpected token ‘(’ 的错误。
是因为linux5.0之后,是不能带有括号的,需要转译,加“\”,改为:pip install --verbose --no-cache-dir torch-spline-conv \ (optional\ )
(5)完成以上四步即证明安装成功啦!