title: Ubuntu 12.04 LTS VirtualBox VM & Python 2.7.3 - 'sudo pip install matplotlib' fatal error
body: <p>I'm installing various Python libraries onto an Ubuntu Linux 12.04 LTS VirtualBox VM which I recently created from scratch. This is so I can do some Python-related university work on my own machine. I was advised in resources given to me by my lecturer to run the following commands to get the packages I need up and running:</p>
  
  <pre><code>$ sudo apt-get install python-dev python-numpy python-numpy-dev python-setuptools python-numpy-dev python-scipy libatlas-dev g++ python-pip cython python-imaging
  $ sudo pip matplotlib scikit-learn scikit-image pybrain PIL
  </code></pre>
  
  <p>I quickly found the 2nd command had an error in it, and so I changed it to <code>$ sudo pip install matplotlib ...</code> before re-running it.</p>
  
  <p>However, during the re-run, I came across an error where matplotlib could not build because Freetype was not installed. And so I followed this Stackoverflow post "<a href="https://stackoverflow.com/questions/20533426/ubuntu-running-pip-install-gives-error-the-following-required-packages-can-no">Ubuntu running `pip install` gives error &#39;The following required packages can not be built: * freetype&#39;</a>" to get the required libfreetype6 package installed on my system.</p>
  
  <p>This leads onto my current problem. My newest attempts to build matplotlib produce an error accompanied with the following wall-of-text 'pip.log' file:</p>
  
  <pre><code>------------------------------------------------------------
  /usr/bin/pip run on Wed Feb 12 14:29:17 2014
  Downloading/unpacking matplotlib
    Running setup.py egg_info for package matplotlib
      ============================================================================
      Edit setup.cfg to change the build options
  
      BUILDING MATPLOTLIB
                  matplotlib: yes [1.3.1]
                      python: yes [2.7.3 (default, Sep 26 2013, 20:08:41)  [GCC
                              4.6.3]]
                    platform: yes [linux2]
  
      REQUIRED DEPENDENCIES AND EXTENSIONS
                       numpy: yes [version 1.6.1]
                    dateutil: yes [using dateutil version 1.5]
                     tornado: yes [tornado was not found. It is required for the
                              WebAgg backend. pip/easy_install may attempt to
                              install it after matplotlib.]
                   pyparsing: yes [pyparsing was not found. It is required for
                              mathtext support. pip/easy_install may attempt to
                              install it after matplotlib.]
                       pycxx: yes [Couldn't import.  Using local copy.]
                      libagg: yes [pkg-config information for 'libagg' could not
                              be found. Using local copy.]
                    freetype: yes [version 14.0.8]
                         png: yes [pkg-config information for 'libpng' could not
                              be found. Using unknown version.]
  
      OPTIONAL SUBPACKAGES
                 sample_data: yes [installing]
                    toolkits: yes [installing]
                       tests: yes [nose 0.11.1 or later is required to run the
                              matplotlib test suite]
  
      OPTIONAL BACKEND EXTENSIONS
                      macosx: no  [Mac OS-X only]
                      qt4agg: no  [PyQt4 not found]
                     gtk3agg: yes [installing, version 3.2.4]
                   gtk3cairo: yes [installing, version 3.2.4]
                      gtkagg: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                              be found.  You may need to install the development
                              package.]
                       tkagg: no  [The C/C++ header for Tk (tk.h) could not be
                              found.  You may need to install the development
                              package.]
                       wxagg: no  [requires wxPython]
                         gtk: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                              be found.  You may need to install the development
                              package.]
                         agg: yes [installing]
                       cairo: yes [installing, version 1.8.8]
                   windowing: no  [Microsoft Windows only]
  
      OPTIONAL LATEX DEPENDENCIES
                      dvipng: no
                 ghostscript: yes [version 9.05]
                       latex: no
                     pdftops: yes [version 0.18.4]
  
      running egg_info
      writing requirements to pip-egg-info/matplotlib.egg-info/requires.txt
      writing pip-egg-info/matplotlib.egg-info/PKG-INFO
      writing namespace_packages to pip-egg-info/matplotlib.egg-info/namespace_packages.txt
      writing top-level names to pip-egg-info/matplotlib.egg-info/top_level.txt
      writing dependency_links to pip-egg-info/matplotlib.egg-info/dependency_links.txt
      warning: manifest_maker: standard file '-c' not found
  
      reading manifest file 'pip-egg-info/matplotlib.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'pip-egg-info/matplotlib.egg-info/SOURCES.txt'
  Requirement already satisfied (use --upgrade to upgrade): numpy&gt;=1.5 in /usr/lib/python2.7/dist-packages (from matplotlib)
  Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /usr/lib/python2.7/dist-packages (from matplotlib)
  Downloading/unpacking tornado (from matplotlib)
    Running setup.py egg_info for package tornado
      running egg_info
      writing requirements to pip-egg-info/tornado.egg-info/requires.txt
      writing pip-egg-info/tornado.egg-info/PKG-INFO
      writing top-level names to pip-egg-info/tornado.egg-info/top_level.txt
      writing dependency_links to pip-egg-info/tornado.egg-info/dependency_links.txt
      warning: manifest_maker: standard file '-c' not found
  
      reading manifest file 'pip-egg-info/tornado.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'pip-egg-info/tornado.egg-info/SOURCES.txt'
    Source in ./build/tornado has version 3.2, which satisfies requirement tornado (from matplotlib)
  Downloading/unpacking pyparsing&gt;=1.5.6,!=2.0.0 (from matplotlib)
    Running setup.py egg_info for package pyparsing
      running egg_info
      writing pip-egg-info/pyparsing.egg-info/PKG-INFO
      writing top-level names to pip-egg-info/pyparsing.egg-info/top_level.txt
      writing dependency_links to pip-egg-info/pyparsing.egg-info/dependency_links.txt
      warning: manifest_maker: standard file '-c' not found
  
      reading manifest file 'pip-egg-info/pyparsing.egg-info/SOURCES.txt'
      writing manifest file 'pip-egg-info/pyparsing.egg-info/SOURCES.txt'
    Source in ./build/pyparsing has version 2.0.1, which satisfies requirement pyparsing&gt;=1.5.6,!=2.0.0 (from matplotlib)
  Downloading/unpacking nose (from matplotlib)
    Running setup.py egg_info for package nose
      running egg_info
      writing pip-egg-info/nose.egg-info/PKG-INFO
      writing top-level names to pip-egg-info/nose.egg-info/top_level.txt
      writing dependency_links to pip-egg-info/nose.egg-info/dependency_links.txt
      writing entry points to pip-egg-info/nose.egg-info/entry_points.txt
      warning: manifest_maker: standard file '-c' not found
  
      reading manifest file 'pip-egg-info/nose.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      no previously-included directories found matching 'doc/.build'
      writing manifest file 'pip-egg-info/nose.egg-info/SOURCES.txt'
    Source in ./build/nose has version 1.3.0, which satisfies requirement nose (from matplotlib)
  Downloading/unpacking backports.ssl-match-hostname (from tornado-&gt;matplotlib)
    Running setup.py egg_info for package backports.ssl-match-hostname
      running egg_info
      writing pip-egg-info/backports.ssl_match_hostname.egg-info/PKG-INFO
      writing top-level names to pip-egg-info/backports.ssl_match_hostname.egg-info/top_level.txt
      writing dependency_links to pip-egg-info/backports.ssl_match_hostname.egg-info/dependency_links.txt
      warning: manifest_maker: standard file '-c' not found
  
      reading manifest file 'pip-egg-info/backports.ssl_match_hostname.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      writing manifest file 'pip-egg-info/backports.ssl_match_hostname.egg-info/SOURCES.txt'
    Source in ./build/backports.ssl-match-hostname has version 3.4.0.2, which satisfies requirement backports.ssl-match-hostname (from tornado-&gt;matplotlib)
  Installing collected packages: matplotlib, tornado, pyparsing, nose, backports.ssl-match-hostname
    Running setup.py install for matplotlib
      Running command /usr/bin/python -c "import setuptools;__file__='/home/jonathan/build/matplotlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-27uup9-record/install-record.txt
      ============================================================================
      Edit setup.cfg to change the build options
  
      BUILDING MATPLOTLIB
                  matplotlib: yes [1.3.1]
                      python: yes [2.7.3 (default, Sep 26 2013, 20:08:41)  [GCC
                              4.6.3]]
                    platform: yes [linux2]
  
      REQUIRED DEPENDENCIES AND EXTENSIONS
                       numpy: yes [version 1.6.1]
                    dateutil: yes [using dateutil version 1.5]
                     tornado: yes [tornado was not found. It is required for the
                              WebAgg backend. pip/easy_install may attempt to
                              install it after matplotlib.]
                   pyparsing: yes [pyparsing was not found. It is required for
                              mathtext support. pip/easy_install may attempt to
                              install it after matplotlib.]
                       pycxx: yes [Couldn't import.  Using local copy.]
                      libagg: yes [pkg-config information for 'libagg' could not
                              be found. Using local copy.]
                    freetype: yes [version 14.0.8]
                         png: yes [pkg-config information for 'libpng' could not
                              be found. Using unknown version.]
  
      OPTIONAL SUBPACKAGES
                 sample_data: yes [installing]
                    toolkits: yes [installing]
                       tests: yes [nose 0.11.1 or later is required to run the
                              matplotlib test suite]
  
      OPTIONAL BACKEND EXTENSIONS
                      macosx: no  [Mac OS-X only]
                      qt4agg: no  [PyQt4 not found]
                     gtk3agg: yes [installing, version 3.2.4]
                   gtk3cairo: yes [installing, version 3.2.4]
                      gtkagg: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                              be found.  You may need to install the development
                              package.]
                       tkagg: no  [The C/C++ header for Tk (tk.h) could not be
                              found.  You may need to install the development
                              package.]
                       wxagg: no  [requires wxPython]
                         gtk: no  [The C/C++ header for gtk (gtk/gtk.h) could not
                              be found.  You may need to install the development
                              package.]
                         agg: yes [installing]
                       cairo: yes [installing, version 1.8.8]
                   windowing: no  [Microsoft Windows only]
  
      OPTIONAL LATEX DEPENDENCIES
                      dvipng: no
                 ghostscript: yes [version 9.05]
                       latex: no
                     pdftops: yes [version 0.18.4]
  
      running install
      running build
      running build_py
      copying lib/matplotlib/mpl-data/matplotlibrc -&gt; build/lib.linux-i686-2.7/matplotlib/mpl-data
      running build_ext
      building 'matplotlib._png' extension
      gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__png_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I/usr/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-i686-2.7/src/_png.o
      src/_png.cpp:10:20: fatal error: png.h: No such file or directory
      compilation terminated.
      error: command 'gcc' failed with exit status 1
      Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/jonathan/build/matplotlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-27uup9-record/install-record.txt:
      ============================================================================
  
  Edit setup.cfg to change the build options
  
  
  
  BUILDING MATPLOTLIB
  
              matplotlib: yes [1.3.1]
  
                  python: yes [2.7.3 (default, Sep 26 2013, 20:08:41)  [GCC
  
                          4.6.3]]
  
                platform: yes [linux2]
  
  
  
  REQUIRED DEPENDENCIES AND EXTENSIONS
  
                   numpy: yes [version 1.6.1]
  
                dateutil: yes [using dateutil version 1.5]
  
                 tornado: yes [tornado was not found. It is required for the
  
                          WebAgg backend. pip/easy_install may attempt to
  
                          install it after matplotlib.]
  
               pyparsing: yes [pyparsing was not found. It is required for
  
                          mathtext support. pip/easy_install may attempt to
  
                          install it after matplotlib.]
  
                   pycxx: yes [Couldn't import.  Using local copy.]
  
                  libagg: yes [pkg-config information for 'libagg' could not
  
                          be found. Using local copy.]
  
                freetype: yes [version 14.0.8]
  
                     png: yes [pkg-config information for 'libpng' could not
  
                          be found. Using unknown version.]
  
  
  
  OPTIONAL SUBPACKAGES
  
             sample_data: yes [installing]
  
                toolkits: yes [installing]
  
                   tests: yes [nose 0.11.1 or later is required to run the
  
                          matplotlib test suite]
  
  
  
  OPTIONAL BACKEND EXTENSIONS
  
                  macosx: no  [Mac OS-X only]
  
                  qt4agg: no  [PyQt4 not found]
  
                 gtk3agg: yes [installing, version 3.2.4]
  
               gtk3cairo: yes [installing, version 3.2.4]
  
                  gtkagg: no  [The C/C++ header for gtk (gtk/gtk.h) could not
  
                          be found.  You may need to install the development
  
                          package.]
  
                   tkagg: no  [The C/C++ header for Tk (tk.h) could not be
  
                          found.  You may need to install the development
  
                          package.]
  
                   wxagg: no  [requires wxPython]
  
                     gtk: no  [The C/C++ header for gtk (gtk/gtk.h) could not
  
                          be found.  You may need to install the development
  
                          package.]
  
                     agg: yes [installing]
  
                   cairo: yes [installing, version 1.8.8]
  
               windowing: no  [Microsoft Windows only]
  
  
  
  OPTIONAL LATEX DEPENDENCIES
  
                  dvipng: no
  
             ghostscript: yes [version 9.05]
  
                   latex: no
  
                 pdftops: yes [version 0.18.4]
  
  
  
  running install
  
  running build
  
  running build_py
  
  copying lib/matplotlib/mpl-data/matplotlibrc -&gt; build/lib.linux-i686-2.7/matplotlib/mpl-data
  
  running build_ext
  
  building 'matplotlib._png' extension
  
  gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib__png_ARRAY_API -DPYCXX_ISO_CPP_LIB=1 -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/local/include -I/usr/include -I. -I/usr/include/python2.7 -c src/_png.cpp -o build/temp.linux-i686-2.7/src/_png.o
  
  src/_png.cpp:10:20: fatal error: png.h: No such file or directory
  
  compilation terminated.
  
  error: command 'gcc' failed with exit status 1
  
  ----------------------------------------
  Command /usr/bin/python -c "import setuptools;__file__='/home/jonathan/build/matplotlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-27uup9-record/install-record.txt failed with error code 1
  Exception information:
  Traceback (most recent call last):
    File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 126, in main
      self.run(options, args)
    File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 228, in run
      requirement_set.install(install_options, global_options)
    File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1093, in install
      requirement.install(install_options, global_options)
    File "/usr/lib/python2.7/dist-packages/pip/req.py", line 566, in install
      cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
    File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 255, in call_subprocess
      % (command_desc, proc.returncode))
  InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/home/jonathan/build/matplotlib/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-27uup9-record/install-record.txt failed with error code 1
  </code></pre>
  
  <p>What is causing my matplotlib build to fail? What can I do to fix it?</p>