diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index a46c62d..862f2d4 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -458,7 +458,11 @@ class TerminalInteractiveShell(InteractiveShell): # code in an empty namespace, and we update *both* user_ns and # user_ns_hidden with this information. ns = {} - gui = pylab_activate(ns, gui, import_all) + try: + gui = pylab_activate(ns, gui, import_all) + except KeyError: + error("Backend %r not supported" % gui) + return self.user_ns.update(ns) self.user_ns_hidden.update(ns) # Now we must activate the gui pylab wants to use, and fix %run to take diff --git a/IPython/lib/pylabtools.py b/IPython/lib/pylabtools.py index ccafe44..8b25a8c 100644 --- a/IPython/lib/pylabtools.py +++ b/IPython/lib/pylabtools.py @@ -196,7 +196,7 @@ def find_gui_and_backend(gui=None): import matplotlib - if gui: + if gui and gui != 'auto': # select backend based on requested gui backend = backends[gui] else: diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 6977d4a..2d138fd 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -740,8 +740,7 @@ class IPKernelApp(KernelApp, InteractiveShellApp): kernel_factory = Kernel if self.pylab: - key = None if self.pylab == 'auto' else self.pylab - gui, backend = pylabtools.find_gui_and_backend(key) + gui, backend = pylabtools.find_gui_and_backend(self.pylab) kernel = kernel_factory(config=self.config, session=self.session, shell_socket=self.shell_socket, diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index cb8f843..5c7d1c9 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -414,7 +414,12 @@ class ZMQInteractiveShell(InteractiveShell): from IPython.zmq.ipkernel import enable_gui opts, arg = self.parse_options(parameter_s, '') if arg=='': arg = None - return enable_gui(arg) + try: + enable_gui(arg) + except Exception as e: + # print simple error message, rather than traceback if we can't + # hook up the GUI + error(str(e)) def enable_pylab(self, gui=None, import_all=True): """Activate pylab support at runtime. @@ -440,13 +445,21 @@ class ZMQInteractiveShell(InteractiveShell): # code in an empty namespace, and we update *both* user_ns and # user_ns_hidden with this information. ns = {} - # override default to inline, from auto-detect - gui = pylabtools.pylab_activate(ns, gui or 'inline', import_all, self) + try: + gui = pylabtools.pylab_activate(ns, gui, import_all, self) + except KeyError: + error("Backend %r not supported" % gui) + return self.user_ns.update(ns) self.user_ns_hidden.update(ns) # Now we must activate the gui pylab wants to use, and fix %run to take # plot updates into account - enable_gui(gui) + try: + enable_gui(gui) + except Exception as e: + # print simple error message, rather than traceback if we can't + # hook up the GUI + error(str(e)) self.magic_run = self._pylab_magic_run