How to know the enabled features of a matplotlib installation?

The optional dependency output you see when installing matplotlib is generated by a set of environment-testers defined in setupext.py. There is a list of these, in the order they are displayed, in setup.py:

mpl_packages = [
    'Building Matplotlib',
    setupext.Matplotlib(),
    setupext.Python(),
    setupext.Platform(),
    'Required dependencies and extensions',
    setupext.Numpy(),
    setupext.Dateutil(),
    setupext.FuncTools32(),
    setupext.Pytz(),
    setupext.Cycler(),
    setupext.Tornado(),
    setupext.Pyparsing(),
    setupext.LibAgg(),
    setupext.FreeType(),
    setupext.FT2Font(),
    setupext.Png(),
    setupext.Qhull(),
    setupext.Image(),
    setupext.TTConv(),
    setupext.Path(),
    setupext.ContourLegacy(),
    setupext.Contour(),
    setupext.Delaunay(),
    setupext.QhullWrap(),
    setupext.Tri(),
    setupext.Externals(),
    'Optional subpackages',
    setupext.SampleData(),
    setupext.Toolkits(),
    setupext.Tests(),
    setupext.Toolkits_Tests(),
    'Optional backend extensions',
    # These backends are listed in order of preference, the first
    # being the most preferred.  The first one that looks like it will
    # work will be selected as the default backend.
    setupext.BackendMacOSX(),
    setupext.BackendQt5(),
    setupext.BackendQt4(),
    setupext.BackendGtk3Agg(),
    setupext.BackendGtk3Cairo(),
    setupext.BackendGtkAgg(),
    setupext.BackendTkAgg(),
    setupext.BackendWxAgg(),
    setupext.BackendGtk(),
    setupext.BackendAgg(),
    setupext.BackendCairo(),
    setupext.Windowing(),
    'Optional LaTeX dependencies',
    setupext.DviPng(),
    setupext.Ghostscript(),
    setupext.LaTeX(),
    setupext.PdfToPs(),
    'Optional package data',
    setupext.Dlls(),
    ]

The actual check is further down in the same file:

for package in mpl_packages:
    if isinstance(package, str):
        print_raw('')
        print_raw(package.upper())
    else:
        try:
            result = package.check()
            if result is not None:
                message = 'yes [%s]' % result
                print_status(package.name, message)
        except setupext.CheckFailed as e:
            msg = str(e).strip()
            if len(msg):
                print_status(package.name, 'no  [%s]' % msg)
            else:
                print_status(package.name, 'no')
            if not package.optional:
                required_failed.append(package)
        else:
            good_packages.append(package)
            if isinstance(package, setupext.OptionalBackendPackage):
                if default_backend is None:
                    default_backend = package.name

Unfortunately, because of how Python installation works neither of these files is available once you’ve installed matplotlib. However, if you have a copy of the matplotlib source (or repo) you can run the checks without performing a complete re-installation of matplotlib, as follows.

First add the matplotlib source folder to your sys.path, and then change directory to the folder (this second step is required for versioneer.py to function).

import os, sys
PATH = r'\your\path\to\matplotlib'
sys.path.append(PATH) 
import setupext # setupext.py contains the dependency definitions

os.chdir(PATH)

Next define the list of packages/dependencies you want to test.

mpl_packages = [
    'Building Matplotlib',
    setupext.Matplotlib(),
    setupext.Python(),
    setupext.Platform(),
    'Required dependencies and extensions',
    setupext.Numpy(),
    setupext.Dateutil(),
    setupext.FuncTools32(),
    setupext.Pytz(),
    setupext.Cycler(),
    setupext.Tornado(),
    setupext.Pyparsing(),
    setupext.LibAgg(),
    setupext.FreeType(),
    setupext.FT2Font(),
    setupext.Png(),
    setupext.Qhull(),
    setupext.Image(),
    setupext.TTConv(),
    setupext.Path(),
    setupext.ContourLegacy(),
    setupext.Contour(),
    setupext.Delaunay(),
    setupext.QhullWrap(),
    setupext.Tri(),
    setupext.Externals(),
    'Optional subpackages',
    setupext.SampleData(),
    setupext.Toolkits(),
    setupext.Tests(),
    setupext.Toolkits_Tests(),
    'Optional backend extensions',
    # These backends are listed in order of preference, the first
    # being the most preferred.  The first one that looks like it will
    # work will be selected as the default backend.
    setupext.BackendMacOSX(),
    setupext.BackendQt5(),
    setupext.BackendQt4(),
    setupext.BackendGtk3Agg(),
    setupext.BackendGtk3Cairo(),
    setupext.BackendGtkAgg(),
    setupext.BackendTkAgg(),
    setupext.BackendWxAgg(),
    setupext.BackendGtk(),
    setupext.BackendAgg(),
    setupext.BackendCairo(),
    setupext.Windowing(),
    'Optional LaTeX dependencies',
    setupext.DviPng(),
    setupext.Ghostscript(),
    setupext.LaTeX(),
    setupext.PdfToPs(),
    'Optional package data',
    setupext.Dlls(),
    ]

Finally, iterate over the optional packages and test them. This cut-down test loop outputs the results for each dependency check without worrying about storing them/etc.

for package in mpl_packages:
    if isinstance(package, str):
        print('')
        print(package.upper())
    else:
        try:
            result = package.check()
            if result is not None:
                message = 'yes [%s]' % result
                print(package.name, message)
        except setupext.CheckFailed as e:
            msg = str(e).strip()
            if len(msg):
                print(package.name, 'no  [%s]' % msg)
            else:
                print(package.name, 'no')

On my current system this gives me the following output:

BUILDING MATPLOTLIB
matplotlib yes [1.5.0+319.g781605a]
python yes [3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit (AMD64)]]
platform yes [win32]

REQUIRED DEPENDENCIES AND EXTENSIONS
numpy yes [version 1.10.4]
dateutil yes [using dateutil version 2.5.2]
functools32 yes [Not required]
pytz yes [using pytz version 2016.3]
cycler yes [using cycler version 0.10.0]
tornado yes [using tornado version 4.3]
pyparsing yes [using pyparsing version 2.0.3]
libagg yes [pkg-config information for 'libagg' could not be found. Using local copy.]
freetype no  [The C/C++ header for freetype (ft2build.h) could not be found.  You may need to install the development package.]
png no  [The C/C++ header for png (png.h) could not be found.  You may need to install the development package.]
qhull yes [pkg-config information for 'qhull' could not be found. Using local copy.]

OPTIONAL SUBPACKAGES
sample_data yes [installing]
toolkits yes [installing]
tests yes [using nose version 1.3.7 / using unittest.mock]
toolkits_tests yes [using nose version 1.3.7 / using unittest.mock]

OPTIONAL BACKEND EXTENSIONS
macosx no  [Mac OS-X only]
qt5agg no  [PyQt5 not found]
qt4agg yes [installing, Qt: 4.8.7, PyQt: 4.8.7; PySide not found]
gtk3agg no  [Requires pygobject to be installed.]
gtk3cairo no  [Requires cairocffi or pycairo to be installed.]
gtkagg no  [Requires pygtk]
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  [Requires pygtk]
agg yes [installing]
cairo no  [cairocffi or pycairo not found]
windowing yes [installing, installing]

OPTIONAL LATEX DEPENDENCIES
dvipng yes [version 1.12]
ghostscript no
latex yes [version MiKTeX 2.9]
pdftops no

OPTIONAL PACKAGE DATA
dlls no  [skipping due to configuration]

Get regular FAQs tips & tutorials direct to your Inbox.

Discussion

Related posts