pyg安装——ERROR: Failed building wheel for torch-sparse

在安装PyG过程中遇到torch-sparse构建轮子失败的问题,通过指定torch-sparse版本为0.6.13解决了初始错误。但随后出现OSError:[WinError127]找不到指定程序的错误,原因是相关包与torch版本不匹配。解决方案是卸载并重新安装与torch版本1.13.0匹配的torch-scatter、torch-sparse、torch-cluster、torch-spline-conv和torch-geometric。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

pyg安装——ERROR: Failed building wheel for torch-sparse

pyg安装的时候最开始还好好的,然后就出现torch-sparse安装出问题了,记录一下解决的办法


torch-sparse安装失败

最近做图神经网络,需要自己安装pyg
在安装好torch之后,我从网上找到了pyg的安装过程

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.10.0+cpu.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.10.0+cpu.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.10.0+cpu.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.10.0+cpu.html
pip install torch-geometri

但是在安装torch-sparse包的时候出现了小问题:
ERROR: Failed building wheel for torch-sparse
在这里插入图片描述
看到了一个大神的解决办法:
解决方法:指定torch-sparse版本

解决方法:指定torch-sparse版本
pip install torch-sparse==0.6.13 -f https://pytorch-geometric.com/whl/torch-1.10.0+cu113.html 

试了试,成功了。

在这里插入图片描述

新的问题 : OSError: [WinError 127] 找不到指定的程序

就是另外的错
原因:根本原因是torch-scatter torch-sparse torch-cluster torch-spline-conv这些关联包跟torch版本不匹配
办法:需要把这些关联包重新装成关联的版本就行了。
具体如下:
(1)卸载掉之前装好的包:torch-scatter torch-sparse torch-cluster torch-spline-conv

pip uninstall  torch-scatter  torch-sparse torch-cluster torch-spline-conv

然后,输入pip list显示自己torch版本:(我在conda环境里输入的)
在这里插入图片描述
由于我的是CPU版本(电脑没有GPU),torch版本为1.13.0,所以我的输入是:(重点在后面的那部分torch-1.13.0+cpu.html)

pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.13.0+cpu.html
pip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.13.0+cpu.html
pip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.13.0+cpu.html
pip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.13.0+cpu.html
pip install torch-geometric

GPU版本可以参考文章:
彻底解决 OSError: [WinError 127] 找不到指定的程序

参考文献:
【图神经网络系列】基于cpu安装PyG
ERROR: Failed building wheel for torch-sparse

conda安装环境出现问题:Building wheels for collected packages: torch-scatter, torch-cluster Building wheel for torch-scatter (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [31 lines of output] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\placeholder.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\scatter.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\segment_coo.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\segment_csr.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\testing.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\utils.py -> build\lib.win-amd64-cpython-38\torch_scatter copying torch_scatter\__init__.py -> build\lib.win-amd64-cpython-38\torch_scatter creating build\lib.win-amd64-cpython-38\torch_scatter\composite copying torch_scatter\composite\logsumexp.py -> build\lib.win-amd64-cpython-38\torch_scatter\composite copying torch_scatter\composite\softmax.py -> build\lib.win-amd64-cpython-38\torch_scatter\composite copying torch_scatter\composite\std.py -> build\lib.win-amd64-cpython-38\torch_scatter\composite copying torch_scatter\composite\__init__.py -> build\lib.win-amd64-cpython-38\torch_scatter\composite running egg_info writing torch_scatter.egg-info\PKG-INFO writing dependency_links to torch_scatter.egg-info\dependency_links.txt writing requirements to torch_scatter.egg-info\requires.txt writing top-level names to torch_scatter.egg-info\top_level.txt reading manifest file 'torch_scatter.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files matching '*' found under directory 'test' adding license file 'LICENSE' writing manifest file 'torch_scatter.egg-info\SOURCES.txt' running build_ext D:\anaconda3\envs\NBFNet\lib\site-packages\torch\utils\cpp_extension.py:304: 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 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for torch-scatter Running setup.py clean for torch-scatter Building wheel for torch-cluster (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [30 lines of output] running bdist_wheel running build running build_py creating build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\fps.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\graclus.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\grid.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\knn.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\nearest.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\radius.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\rw.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\sampler.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\testing.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\typing.py -> build\lib.win-amd64-cpython-38\torch_cluster copying torch_cluster\__init__.py -> build\lib.win-amd64-cpython-38\torch_cluster running egg_info writing torch_cluster.egg-info\PKG-INFO writing dependency_links to torch_cluster.egg-info\dependency_links.txt writing requirements to torch_cluster.egg-info\requires.txt writing top-level names to torch_cluster.egg-info\top_level.txt reading manifest file 'torch_cluster.egg-info\SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no previously-included files matching '*' found under directory 'test' adding license file 'LICENSE' writing manifest file 'torch_cluster.egg-info\SOURCES.txt' running build_ext D:\anaconda3\envs\NBFNet\lib\site-packages\torch\utils\cpp_extension.py:304: UserWarning: Error checking compiler version for cl: [WinError 2] 系统找不到指定的文件。 warnings.warn(f'Error checking compiler version for {compiler}: {error}') building 'torch_cluster._fps_cpu' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for torch-cluster Running setup.py clean for torch-cluster Failed to build torch-scatter torch-cluster ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (torch-scatter, torch-cluster)
最新发布
06-23
### 安装 PyG-Lib 及其依赖项 为了成功安装 PyG-Lib (PyTorch Geometric) 和其依赖项 `torch-scatter`, `torch-sparse`, `torch-cluster`, `torch-spline-conv` 以及 `torch-geometric`,建议遵循官方推荐的方法来确保兼容性和稳定性。 对于特定版本的 PyTorch 和 CUDA,可以使用如下命令进行安装: ```bash pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-{version}+cu{version}.html[^1] ``` 这里 `{version}` 需要替换为实际使用的 PyTorch 版本号和 CUDA 版本号。例如,如果使用的是 PyTorch 1.12.0 和 CUDA 11.3,则 URL 应该设置为 `https://data.pyg.org/whl/torch-1.12.0+cu113.html`. 需要注意的是,在某些情况下最新版的 PyTorch 或者 PyTorch Geometric 可能尚未完全适配所有环境配置[^2]。因此,当遇到安装问题时,可以选择指定较低版本的 PyTorch 来保证兼容性。比如通过 Conda 安装特定版本的 PyTorch: ```bash conda install pytorch=1.10 torchvision torchaudio cudatoolkit=10.2 -c pytorch ``` 另外一种方式是单独依次安装各个依赖库,并明确指明它们所基于的 PyTorch 和 CUDA 的具体版本: ```bash 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 pip install torch_geometric[^3] ``` 此过程可能会比较耗时,请保持耐心等待完成。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值