From 9be9a917e6f08e9e3379198256419e25718f2059 2013-07-12 12:45:58 From: Matthias Bussonnier Date: 2013-07-12 12:45:58 Subject: [PATCH] Merge pull request #3608 from ivanov/nicer-backend-msg a nicer error message when using %pylab magic If the user specified an unsupported backend, there was no indication for what the valid names were. Error message prior to this commit: In[1]: %pylab xxx ERROR: Backend u'xxx' not supported. after this commit: In[1]: %pylab xxx ERROR: Backend 'xxx' not supported. Supported backends are: gtk inline osx qt qt4 tk wx --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index af58c28..db88ce5 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2852,7 +2852,7 @@ class InteractiveShell(SingletonConfigurable): make sense in all contexts, for example a terminal ipython can't display figures inline. """ - from IPython.core.pylabtools import mpl_runner + from IPython.core.pylabtools import mpl_runner, backends # We want to prevent the loading of pylab to pollute the user's # namespace as shown by the %who* magics, so we execute the activation # code in an empty namespace, and we update *both* user_ns and @@ -2861,7 +2861,8 @@ class InteractiveShell(SingletonConfigurable): try: gui = pylab_activate(ns, gui, import_all, self, welcome_message=welcome_message) except KeyError: - error("Backend %r not supported" % gui) + error("Backend '%s' not supported. Supported backends are: %s" + % (gui, " ".join(sorted(backends.keys())))) return except ImportError: error("pylab mode doesn't work as matplotlib could not be found." + \