首页 > 解决方案 > 在 Windows 上安装 Matplotlib 错误 - 无法打开包含文件 'ft2build.h'

问题描述

我正在尝试matplotlib使用以下方式安装:

pip install matplotlib

但是,我不断收到此错误:

- cannot open include file 'ft2build.h' no such file or directory

错误图像

标签: pythonmatplotlibpip

解决方案


您正在使用 python 3.8,其中没有可用的预构建whl文件pypi,因此您pip正在尝试从源代码构建 matplotlib。为此,您需要下载并安装matplotlib. 在这种情况下,ft2build.h缺少哪个是freetype库的一部分。

如果你真的想从源代码构建,matplotlib 开发人员提供了一个基于脚本的解决方案来下载和安装所有必需的依赖项。


由于您可能不关心从源代码构建(这在 Windows 上可能会做很多工作),因此您应该考虑以下选项之一:

  1. whl安装除 3.8 以外的 python 版本,它是非常新的,因此对于您要使用的模块,并不总是有官方的预构建文件
  2. 正如 MrFuppes 建议的那样,matplotlib‑3.2.0rc1‑cp38‑cp38‑win_amd64.whl这个非官方的 whl 文件集合中下载并pip install matplotlib‑3.2.0rc1‑cp38‑cp38‑win_amd64.whl在您的 cmd 中执行

推荐阅读