torch_geometric和torch-sparse、torch-scatter的安装报错

1 问题

安装torch-geometric没报错,导入包时需要torch-sparse,geometric包需要这个依赖。
所以就安装torch-sparse,但是一直报错,类似于:

ERROR: Command errored out with exit status 1: command: 'C:\Users\hastings\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\hastings\AppData\Local\Temp\pip-install-ks3umk5s\torch-scatter\setup.py'"'"'; file='"'"'C:\Users\hastings\AppData\Local\Temp\pip-install-ks3umk5s\torch-scatter\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\hastings\AppData\Local\Temp\pip-wheel-aw7g1z08' cwd: C:\Users\hastings\AppData\Local\Temp\pip-install-ks3umk5s\torch-scatter
Complete output (27 lines): running bdist_wheel running build running build_py creating build creating build\lib.win-amd64-3.8 creating build\lib.win-amd64-3.8\torch_scatter copying torch_scatter\placeholder.py -> build\lib.win-amd64-3.8\torch_scatter copying torch_scatter\scatter.py -> build\lib.win-amd64-3.8\torch_scatter copying torch_scatter\segment_coo.py -> build\lib.win-amd64-3.8\torch_scatter copying torch_scatter\segment_csr.py -> build\lib.win-amd64-3.8\torch_scatter copying torch_scatter\utils.py -> build\lib.win-amd64-3.8\torch_scatter copying torch_scatter_init_.py -> build\lib.win-amd64-3.8\torch_scatter creating build\lib.win-amd64-3.8\torch_scatter\composite copying torch_scatter\composite\logsumexp.py -> build\lib.win-amd64-3.8\torch_scatter\composite copying torch_scatter\composite\softmax.py -> build\lib.win-amd64-3.8\torch_scatter\composite copying torch_scatter\composite\std.py -> build\lib.win-amd64-3.8\torch_scatter\composite copying torch_scatter\composite_init_.py -> build\lib.win-amd64-3.8\torch_scatter\composite running build_ext C:\Users\hastings\anaconda3\lib\site-packages\torch\utils\cpp_extension.py:346: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。 warnings.warn(f'Error checking compiler version for {compiler}: {error}') building 'torch_scatter._scatter_cpu' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/ Error in atexit._run_exitfuncs: Traceback (most recent call last): File "C:\Users\hastings\anaconda3\lib\site-packages\colorama\ansitowin32.py", line 59, in closed return stream.closed

ValueError: underlying buffer has been detached


ERROR: Failed building wheel for torch-scatter

然后就一直搜是什么问题,看这上面的意思是需要Microsoft Visual C++ 14.0 is required,但是我之前好像已经安装了这个。

尝试不下于:

  1. 匹配 PyTorch的版本和PyG的版本,还是报错
  2. 都卸载了先安装torch-sparse...
    ...

都没用。

然后我把包下载到本地,然后用绝对路径安装,就不报错了,虽然不知道为什么。。。
如下
👇
👇
👇

Step1:去PyG的官网

torch-geometric

image

Step2:然后找到下面安装的部分

image

这里要求的PyTorch版本为1.12.0,也有很多之前发布的版本

Step3:进入上面的here

点击here,可以看到对应不同的torch版本,适配的torch-scatter等包

image

选择自己适合的,点进去:

Step4:下载对应的包到本地

image

根据你的操作系统、和你的python版本(通过python --version可以查看)选择对应的轮子下载到本地

Step5:安装本地的包

win+r打开cmd,找到之前下载的轮子:

image

使用pip install 绝对路径,就能顺利安装了。

posted @ 2022-11-03 19:42  A07_xxxx  阅读(2613)  评论(0编辑  收藏  举报