conda创建虚拟环境
conda create -n pytorch python=3.7
conda activate pytorch
安装cuda
nvidia-smi
![在这里插入图片描述](https://img-blog.csdnimg.cn/277e8d60ecfd47b8ba0b9897ab5e21e7.png#pic_center)
右上角的CUDA VERSION 就是可以安装cuda的最高版本了。
安装cuda:
conda install cudatoolkit=10.0
安装pytorch
pytoch 官网地址,这里可以选择合适的版本:
以前的pytorch:
这里要注意conda的换源问题,不然很慢。
检查:
python -c "import torch; print(torch.version.cuda)"
安装依赖
下载包
cu92就是cuda9.2,cp38就是python3.8,然后选择环境linux,最终选择合适的torch-scatter、torch-sparse、torch-cluster以及torch-spline-conv包下载:
然后安装:
pip install torch_cluster-1.5.8-cp37-cp37m-linux_x86_64.whl
pip install torch_scatter-2.0.5-cp37-cp37m-linux_x86_64.whl
pip install torch_sparse-0.6.9-cp37-cp37m-linux_x86_64.whl
pip install torch_spline_conv-1.2.0+cu101-cp37-cp37m-linux_x86_64.whl
最后安装torch-geometric:
pip install torch-geometric
测试安装是否成功:
python -c "import torch_geometric"
安装成功,但有报错:
from torch.profiler import ProfilerActivity, profile
查询得知,torch.profiler为1.8.1后的新增功能,之前旧版本类似功能是torch.autograd.profiler,但没有ProfilerActivity,此时意识到应该是torch-geometric版本安装错了,各种教程一直强调torch-scatter、torch-sparse、torch-cluster以及torch-spline-conv的版本匹配,忽略了直接pip install torch-geometric就是最新的,所以要选择匹配torch1.7的torch-geometric:
先卸载再安装:
pip uninstall torch_geometric
pip install torch_geometric==1.6.3
import torch_geometric 检测安装成功!