ipython / ipython

Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.
https://ipython.readthedocs.org
BSD 3-Clause "New" or "Revised" License
16.25k stars 4.43k forks source link

[prompt toolkit] Fail more gracefully on matplotlib inline #9264

Closed Carreau closed 8 years ago

Carreau commented 8 years ago

Which does not (always?) make sens in terminal.

Except on iterm2 :-) CC @takluyver

 matplotlib inline
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-e27d371d6baa> in <module>()
----> 1 get_ipython().magic('matplotlib inline')

/Users/bussonniermatthias/dev/ipython/IPython/core/interactiveshell.py in magic(self, arg_s)
   2162         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2163         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2164         return self.run_line_magic(magic_name, magic_arg_s)
   2165
   2166     #-------------------------------------------------------------------------

/Users/bussonniermatthias/dev/ipython/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
   2083                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2084             with self.builtin_trap:
-> 2085                 result = fn(*args,**kwargs)
   2086             return result
   2087

<decorator-gen-105> in matplotlib(self, line)

/Users/bussonniermatthias/dev/ipython/IPython/core/magic.py in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    194
    195         if callable(arg):

/Users/bussonniermatthias/dev/ipython/IPython/core/magics/pylab.py in matplotlib(self, line)
     98             print("Available matplotlib backends: %s" % backends_list)
     99         else:
--> 100             gui, backend = self.shell.enable_matplotlib(args.gui)
    101             self._show_matplotlib_backend(args.gui, backend)
    102

/Users/bussonniermatthias/dev/ipython/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
   2955         # Now we must activate the gui pylab wants to use, and fix %run to take
   2956         # plot updates into account
-> 2957         self.enable_gui(gui)
   2958         self.magics_manager.registry['ExecutionMagics'].default_runner = \
   2959             pt.mpl_runner(self.safe_execfile)

/Users/bussonniermatthias/dev/ipython/IPython/terminal/ptshell.py in enable_gui(self, gui)
    233     def enable_gui(self, gui=None):
    234         if gui:
--> 235             self._inputhook = get_inputhook_func(gui)
    236         else:
    237             self._inputhook = None

/Users/bussonniermatthias/dev/ipython/IPython/terminal/pt_inputhooks/__init__.py in get_inputhook_func(gui)
     13         os.environ['QT_API'] = 'pyqt5'
     14
---> 15     mod = importlib.import_module('IPython.terminal.pt_inputhooks.'+gui)
     16     return mod.inputhook

/Users/bussonniermatthias/anaconda3/lib/python3.5/importlib/__init__.py in import_module(name, package)
    124                 break
    125             level += 1
--> 126     return _bootstrap._gcd_import(name[level:], package, level)
    127
    128

/Users/bussonniermatthias/anaconda3/lib/python3.5/importlib/_bootstrap.py in _gcd_import(name, package, level)

/Users/bussonniermatthias/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load(name, import_)

/Users/bussonniermatthias/anaconda3/lib/python3.5/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ImportError: No module named 'IPython.terminal.pt_inputhooks.inline'
takluyver commented 8 years ago

We could catch the ImportError and display a shorter message, but that could obscure the real cause of the error - e.g. if you do %gui qt when you don't have any Qt library installed, the error message shouldn't say that 'qt' is not a supported option.

I guess we could just check a list of supported backends and throw an error if it's not on there.

Carreau commented 8 years ago

I guess we could just check a list of supported backends and throw an error if it's not on there.

That's what we do with normal TIS.