diff --git a/sos/jupyter/kernel.py b/sos/jupyter/kernel.py
index <HASH>..<HASH> 100644
--- a/sos/jupyter/kernel.py
+++ b/sos/jupyter/kernel.py
@@ -1025,8 +1025,11 @@ class SoS_Kernel(Kernel):
             return self._do_execute(remaining_code, silent, store_history, user_expressions, allow_stdin)
         elif self.MAGIC_MATPLOTLIB.match(code):
             options, remaining_code = self.get_magic_and_code(code, False)
-            self.shell.enable_gui = lambda gui: None
-            gui, backend = self.shell.enable_matplotlib(options)
+            try:
+                self.shell.enable_gui = lambda gui: None
+                gui, backend = self.shell.enable_matplotlib(options)
+            except Exception as e:
+                self.warn('Failed to set matplotlib backnd {}: {}'.format(options, e))
             return self._do_execute(remaining_code, silent, store_history, user_expressions, allow_stdin)
         elif self.MAGIC_SET.match(code):
             options, remaining_code = self.get_magic_and_code(code, False)
Display error message of enable_matplotlib, this magic still does not work though.