![72d26ae5f96ab895e7e9c3edd2b59d44.png](https://img-blog.csdnimg.cn/img_convert/72d26ae5f96ab895e7e9c3edd2b59d44.png)
准备工作(自己的电脑):
- OS: Ubuntu 16.04
- Python version: 3.6
- PyTorch version: 1.6.0
- CUDA version: 10.1
安装流程(pip):
- 首先确保PyTorch 1.4.0 及以上版本
$ python -c "import torch; print(torch.__version__)"
>>> 1.6.0
2. 查询GPU版PyTorch的CUDA版本
$ python -c "import torch; print(torch.version.cuda)"
>>> 10.1
3. 安装依赖包
$ pip install torch-scatter==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
$ pip install torch-sparse==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
$ pip install torch-cluster==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
$ pip install torch-spline-conv==latest+cu101 -f https://pytorch-geometric.com/whl/torch-1.6.0.html
$ pip install torch-geometric
其中“cu101” 和 “torch-1.6.0” 可依据自己的配置来选择
4. 测试是否安装成功
$ python
>>> import torch
>>> from torch_geometric.data import Data
OSError: libcusparse.so.10: cannot open shared object file: No such file or directory
显然,未能成功安装。
修复流程
1. 检查 nvcc
$ nvcc --version
-base:/usr/lib/command-not-found:/usr/bin/python3: bad interpreter: No such file or directory
又出问题!既然不识别命令,那就安装呗~
2. 打开terminal
$ nano /home/username/.bashrc
# or
$ nano /home/$USER/.bashrc
3. 添加以下命令行
export PATH="/usr/local/cuda-10.1/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-10.1/lib64:$LD_LIBRARY_PATH"
4. 保存并关闭terminal
On you keyboard press the following:
ctrl + o --> save
enter or return key --> accept changes
ctrl + x --> close editor
5. 运行nvcc(一定要确保PyTorch和CUDA的版本一致)
$ nvcc --version
>>> 10.1
$ python -c "import torch; print(torch.version.cuda)"
>>> 10.1
6. 再次测试是否安装成功
import torch
from torch_geometric.data import Data
edge_index = torch.tensor([[0, 1, 1, 2],
[1, 0, 2, 1]], dtype=torch.long)
x = torch.tensor([[-1], [0], [1]], dtype=torch.float)
data = Data(x=x, edge_index=edge_index)
>>> print(data.keys)
>>> ['x', 'edge_index']