安装pytorch geometric提示torch-scatter安装失败的解决办法

最近重装电脑之后发现pytorch geometric的安装竟然报错了,在网上找了一番才找到办法
在这里记录一下

根据pytorch geometric给出的安装命令

pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.8.0+cu102.html

在安装时可能会看到报错信息如下

C:\ProgramData\Anaconda3\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/
  Error in atexit._run_exitfuncs:
  Traceback (most recent call last):
    File "C:\ProgramData\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 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

这个意思好像是在说torch-scatter需要先编译再安装,而我们本地没有编译工具,从而无法编译成wheel,既然这样的话,那就按照它给的地址直接下载一个就可以了
安装pytorch geometric提示torch-scatter安装失败的解决办法_第1张图片

直接把这个勾上,然后安装
安装pytorch geometric提示torch-scatter安装失败的解决办法_第2张图片
安装完成后继续执行命令

pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.8.0+cu102.html

可以看到安装成功

(base) PS C:\WINDOWS\system32> pip install torch-scatter torch-sparse torch-cluster torch-spline-conv torch-geometric -f https://data.pyg.org/whl/torch-1.8.0+cu102.html
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Looking in links: https://data.pyg.org/whl/torch-1.8.0+cu102.html
Collecting torch-scatter
  Using cached https://mirrors.aliyun.com/pypi/packages/1b/a0/6e44e887eb7fff78a9642035fe9662fc22c850a377369a52f308dd553104/torch_scatter-2.0.9.tar.gz (21 kB)
Requirement already satisfied: torch-sparse in c:\programdata\anaconda3\lib\site-packages (0.6.12)
Collecting torch-cluster
  Using cached https://data.pyg.org/whl/torch-1.8.0%2Bcu102/torch_cluster-1.5.9-cp38-cp38-win_amd64.whl (1.4 MB)
Requirement already satisfied: torch-spline-conv in c:\programdata\anaconda3\lib\site-packages (1.2.1)
Collecting torch-geometric
  Using cached torch_geometric-2.0.2-py3-none-any.whl
Requirement already satisfied: tqdm in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (4.59.0)
Requirement already satisfied: yacs in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (0.1.8)
Requirement already satisfied: networkx in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (2.5)
Requirement already satisfied: PyYAML in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (5.4.1)
Requirement already satisfied: googledrivedownloader in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (0.4)
Requirement already satisfied: jinja2 in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (2.11.3)
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (1.20.1)
Requirement already satisfied: requests in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (2.25.1)
Requirement already satisfied: scikit-learn in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (0.24.1)
Requirement already satisfied: pandas in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (1.2.4)
Requirement already satisfied: scipy in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (1.6.2)
Requirement already satisfied: pyparsing in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (2.4.7)
Requirement already satisfied: rdflib in c:\programdata\anaconda3\lib\site-packages (from torch-geometric) (6.0.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:\programdata\anaconda3\lib\site-packages (from jinja2->torch-geometric) (1.1.1)
Requirement already satisfied: decorator>=4.3.0 in c:\programdata\anaconda3\lib\site-packages (from networkx->torch-geometric) (5.0.6)
Requirement already satisfied: pytz>=2017.3 in c:\programdata\anaconda3\lib\site-packages (from pandas->torch-geometric) (2021.1)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\programdata\anaconda3\lib\site-packages (from pandas->torch-geometric) (2.8.1)
Requirement already satisfied: six>=1.5 in c:\programdata\anaconda3\lib\site-packages (from python-dateutil>=2.7.3->pandas->torch-geometric) (1.15.0)
Requirement already satisfied: setuptools in c:\programdata\anaconda3\lib\site-packages (from rdflib->torch-geometric) (52.0.0.post20210125)
Requirement already satisfied: isodate in c:\programdata\anaconda3\lib\site-packages (from rdflib->torch-geometric) (0.6.0)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\programdata\anaconda3\lib\site-packages (from requests->torch-geometric) (1.26.4)
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\anaconda3\lib\site-packages (from requests->torch-geometric) (2020.12.5)
Requirement already satisfied: chardet<5,>=3.0.2 in c:\programdata\anaconda3\lib\site-packages (from requests->torch-geometric) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in c:\programdata\anaconda3\lib\site-packages (from requests->torch-geometric) (2.10)
Requirement already satisfied: threadpoolctl>=2.0.0 in c:\programdata\anaconda3\lib\site-packages (from scikit-learn->torch-geometric) (2.1.0)
Requirement already satisfied: joblib>=0.11 in c:\programdata\anaconda3\lib\site-packages (from scikit-learn->torch-geometric) (1.0.1)
Building wheels for collected packages: torch-scatter
  Building wheel for torch-scatter (setup.py) ... done
  Created wheel for torch-scatter: filename=torch_scatter-2.0.9-cp38-cp38-win_amd64.whl size=3221735 sha256=01eee14deb693095afc9851742a41d5c6533355ca1681b6a01aeb864bddfece7
  Stored in directory: c:\users\77231\appdata\local\pip\cache\wheels\41\dd\3e\7cb34126e9979403b2ce2f7296c9b3aa5cfe0f218aa8e86e03
Successfully built torch-scatter
Installing collected packages: torch-scatter, torch-geometric, torch-cluster
Successfully installed torch-cluster-1.5.9 torch-geometric-2.0.2 torch-scatter-2.0.9
(base) PS C:\WINDOWS\system32>

你可能感兴趣的:(pytorch,人工智能,python)