[Biopython-dev] Enhancements to Phylo.draw; pyplot best practices

Eric Talevich eric.talevich at gmail.com
Tue Apr 17 04:17:26 UTC 2012


On Mon, Apr 16, 2012 at 11:20 AM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
> Hi Eric,
>
> That seems to have caused a test failure on one of our buildslaves:
>
> ======================================================================
> ERROR: Run the tree layout algorithm, but don't display it.
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>  File "/home/buildslave/BuildBot/lin2664/build/Tests/test_Phylo_depend.py",
> line 51, in test_draw
>    Phylo.draw(dollo, do_show=False)
>  File "/home/buildslave/BuildBot/lin2664/build/build/lib.linux-x86_64-2.6/Bio/Phylo/_utils.py",
> line 366, in draw
>    fig = plt.figure()
>  File "/usr/local/lib/python2.6/site-packages/matplotlib/pyplot.py",
> line 270, in figure
>    **kwargs)
>  File "/usr/local/lib/python2.6/site-packages/matplotlib/backends/backend_wxagg.py",
> line 120, in new_figure_manager
>    backend_wx._create_wx_app()
>  File "/usr/local/lib/python2.6/site-packages/matplotlib/backends/backend_wx.py",
> line 1377, in _create_wx_app
>    wxapp = wx.PySimpleApp()
>  File "/usr/local/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py",
> line 8078, in __init__
>    wx.App.__init__(self, redirect, filename, useBestVisual, clearSigInt)
>  File "/usr/local/lib/python2.6/site-packages/wx-2.8-gtk2-unicode/wx/_core.py",
> line 7946, in __init__
>    raise SystemExit(msg)
> SystemExit: Unable to access the X Display, is $DISPLAY set properly?
>
> ----------------------------------------------------------------------
>
> http://testing.open-bio.org:8010/builders/Linux%2064%20-%20Python%202.6/builds/534/steps/shell/logs/stdio
> http://testing.open-bio.org:8010/builders/Linux%2064%20-%20Python%202.6/builds/535/steps/shell/logs/stdio
>
> Interestingly the same machine is passing the tests under other Python versions.
> That would seem to rule out the $DISPLAY environment variable being the cause.
> My hunch would be this is something about the Python 2.6 install, perhaps it
> is missing some library (wxPython maybe).
>
> Logged in as the buildslave on this machine I can see that both Python 2.6 & 2.7
> have the same version of matplotlib installed, but only one is failing the test:
>
> $ python2.5
> Python 2.5.5 (r255:77872, Jan 14 2011, 17:09:55)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import matplotlib
> Traceback (most recent call last):
>  File "<stdin>", line 1, in <module>
> ImportError: No module named matplotlib
>
> $ python2.6
> Python 2.6.6 (r266:84292, Aug 31 2010, 16:21:14)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import matplotlib
>>>> matplotlib.__version__
> '1.0.0'
>
> $ python2.7
> Python 2.7 (r27:82500, Jul 13 2010, 14:02:41)
> [GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import matplotlib
>>>> matplotlib.__version__
> '1.0.0'
>
>
> Peter


Actually, it was this commit which added new unit tests:
https://github.com/biopython/biopython/commit/a5f995bc1d9e113d88195cc7ae6f389984d762d8

On my machine with Python 2.6 and Ubuntu, the test passes, so I'm not
sure how to debug this, exactly. Do you know a way to prevent
matplotlib from attempting to launch the Wx app, beyond turn off
interactive mode as the test already does?

One idea is to specify a matplotlib backend other than wx. For
example, using this import approach in test_Phylo_depend.py might do
the trick:

try:
    import matplotlib
except ImportError:
    raise MissingExternalDependencyError(
            "Install matplotlib if you want to use Bio.Phylo._utils.")
else:
    # Don't use the Wx backend for matplotlib, b/c that depends on Wx being
    # properly set up on the build machine. Instead, use the simpler postscript
    # backend -- we're not going to display or save the plot anyway, so it
    # doesn't matter much, as long as it's not Wx. I guess.
    matplotlib.use("ps")
    from matplotlib import pyplot


Would you be able to test this on the errant buildbot machine without
having to commit this to the trunk?


Thanks,
Eric




More information about the Biopython-dev mailing list