首页 > 解决方案 > 在 windows 上安装 matplotlib 的问题

问题描述

我正在尝试在 Windows 上安装 matplotlib,但出现错误:

* The following required packages can not be built:
                            * freetype, png
                            * Please check http://gnuwin32.sourceforge.net/packa
                            * ges/freetype.htm for instructions to install
                            * freetype
                            * Please check http://gnuwin32.sourceforge.net/packa
                            * ges/libpng.htm for instructions to install png

虽然我已经通过 pip install 命令安装了两者:

C:\Users\Andrzej\AppData\Local\Programs\Python\Python37\Scripts>pip install freetype-py
Requirement already satisfied: freetype-py in c:\users\andrzej\appdata\local\programs\python\python37\lib\site-packages (1.2.1)

C:\Users\Andrzej\AppData\Local\Programs\Python\Python37\Scripts>pip install pypng
Requirement already satisfied: pypng in c:\users\andrzej\appdata\local\programs\python\python37\lib\site-packages (0.0.18). 

我会很感激你的帮助。最好的

标签: windowsmatplotlib

解决方案


错误消息中列出的 freetype 和 libpng 包是 C 库,需要安装在您的系统上以便 matplotlib 构建。不幸的是,freetype-py 和 pypng 与 C 库完全分开,不提供 matplotlib 需要的文件。

由于您可能不想自己编译这两个库,因此最好的选择是使用二进制轮安装 matplotlib,其中将包含丢失的文件。

Wheels 是为 Python 的最新稳定版本构建的,通常在可用时由 pip 使用。除非您有特殊原因运行 Python 的候选发布版本,否则您会发现通过切换到最新的稳定版本(撰写本文时为 3.6),包安装通常会减少问题。那么pip install matplotlib应该就是你所需要的。

如果您必须使用候选发布版,您可以从Christoph Gohlke 的非官方包下载为它构建的轮子。


推荐阅读