背景说明
在导入torch_geometric这个模块时,遇到了以下报错“Could not find module 'D:\Anaconda\envs\DL\Lib\site-packages\torch_cluster_grid_cuda.pyd' (or one of its dependencies). Try using the full path with constructor syntax”。
前一段时间时没有问题的,今天突然出现了这个问题。各种版本号都是匹配的,在绝对路径中这个文件也是存在的,不知道为什么,于是决定重新安装PyTorch Geometric (PyG) 库。
1.卸载旧的版本
pip uninstall torch_geometric torch_scatter torch_sparse torch_cluster torch_spline_conv
2.重新安装
①检查自己的 torch 和 cuda版本。
import torch
print(torch.__version__)
#检查torch版本;
import torch
print(torch.version.cuda)
#检查cuda版本;
以我的为例:
②安装相关依赖。依赖来源在这里pytorch-geometric.com/whl/
先安装4个,分别是1.torch-scatter 2.torch-sparse 3.torch-cluster 4.torch-spline-conv。注意修改对应的版本号。这个过程可能有一点慢,需要耐心等等。
pip install torch_scatter -f https://pytorch-geometric.com/whl/torch-1.12.0%2Bcu113.html
pip install torch_sparse -f https://pytorch-geometric.com/whl/torch-1.12.0%2Bcu113.html
pip install torch_cluster -f https://pytorch-geometric.com/whl/torch-1.12.0%2Bcu113.html
pip install torch_spline_conv -f https://pytorch-geometric.com/whl/torch-1.12.0%2Bcu113.html
如果是torch2.0.0,cuda117,就改成对应的torch-2.0.0%2Bcu117,以此类推。
其他问题:
我在进行这一步时遇到了编译失败的问题,原因是没有Microoft C+ Build Tools。在给出网站下载安装后就可以顺利编译了,并且成功安装。
③下载安装完这四个文件以后还需要做一件事情,利用镜像源下载一个安装包:
pip install -U -i https://pypi.tuna.tsinghua.edu.cn/simple torch_geometric
最后打开JupyterNotebook导入需要的包,没有前面的报错,安装完毕。
3.总结
重新安装之后每个依赖都换成了更新的版本,新的版本可以正常使用。所以我认为是版本更新导致的问题。不知道和安装Microoft C+ Build Tools有没有关系。希望得到大佬的指点!!!