Repository: pandas-dev/pandas

Issue:
Default docs builds to a non-interactive matplotlib backend
`python make.py html` fails on Mac OS in a virtualenv, using a Python interpreter installed with pyenv, because the interpreter isn't a framework build, and matplotlib defaults to using the macosx interactive backend, which requires a framework build of the interpreter.

I think the docs build doesn't require an interactive backend and it should be safe to use Agg, which is available on all platforms.

The failure looks like:
```
(pandas-dev) tsmith-0yhv2t:tsmith doc (master *)$ python make.py html
Running Sphinx v1.7.5

Configuration error:
There is a programable error in your configuration file:

Traceback (most recent call last):
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/site-packages/sphinx/config.py", line 161, in __init__
    execfile_(filename, config)
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/site-packages/sphinx/util/pycompat.py", line 150, in execfile_
    exec_(code, _globals)
  File "conf.py", line 285, in <module>
    klass = getattr(importlib.import_module(mod), classname)
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/tsmith/upstream/pandas/pandas/io/formats/style.py", line 34, in <module>
    import matplotlib.pyplot as plt
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/Users/tsmith/.pyenv/versions/3.6.4/envs/pandas-dev/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
    from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.
```


Discussion:

Resolving patch:
diff --git a/doc/make.py b/doc/make.py
--- a/doc/make.py
+++ b/doc/make.py
@@ -363,6 +363,10 @@ def main():
     sys.path.append(args.python_path)
     globals()['pandas'] = importlib.import_module('pandas')
 
+    # Set the matplotlib backend to the non-interactive Agg backend for all
+    # child processes.
+    os.environ['MPLBACKEND'] = 'module://matplotlib.backends.backend_agg'
+
     builder = DocBuilder(args.num_jobs, not args.no_api, args.single,
                          args.verbosity)
     getattr(builder, args.command)()


Test patch: