pip安装matplotlib报错

1.出现如下错误

Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/1e/20/2032ad99f0dfe0f60970941af36e8d0942d3713f442bb3df37ac35d67358/matplotlib-2.2.4.tar.gz (37.0MB)
     |████████████████████████████████| 37.0MB 97kB/s
    ERROR: Command errored out with exit status 1:
         cwd: /tmp/pip-install-54xHey/matplotlib/
    Complete output (61 lines):
    ============================================================================
    Edit setup.cfg to change the build options
    BUILDING MATPLOTLIB
                matplotlib: yes [2.2.4]
                    python: yes [2.7.12 (default, Oct  8 2019, 14:14:10)  [GCC
                            5.4.0 20160609]]
                  platform: yes [linux2]
    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.11.0]
          install_requires: yes [handled by setuptools]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: no  [pkg-config information for 'libpng' could not
                            be found.]
                     qhull: yes [pkg-config information for 'libqhull' could not
                            be found. Using local copy.]
    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: no  [skipping due to configuration]
            toolkits_tests: no  [skipping due to configuration]
    OPTIONAL BACKEND EXTENSIONS
                    macosx: no  [Mac OS-X only]
                    qt5agg: no  [PySide2 not found; PyQt5 not found]
                    qt4agg: no  [PySide not found; PyQt4 not found]
                   gtk3agg: no  [Requires pygobject to be installed.]
                 gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: yes [installing; run-time loading from Python Tcl /
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairocffi or pycairo not found]
                 windowing: no  [Microsoft Windows only]
    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: yes [version 9.26]
                     latex: no
                   pdftops: yes [version 0.41.0]
    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]
    ============================================================================
                            * The following required packages can not be built:
                            * freetype, png
                            * Try installing freetype with `apt-get install
                            * libfreetype6-dev` and pkg-config with `apt-get
                            * install pkg-config`
                            * Try installing png with `apt-get install
                            * libpng12-dev` and pkg-config with `apt-get install
                            * pkg-config`
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

2.安装依赖库

$ sudo apt-get install libpng*