%matplotlib内联:'NoneType'对象没有属性'is_interactive'

时间:2016-10-30 03:01:37

标签: python matplotlib ipython

我不知道为什么会这样。我该如何解决?

In [1]: %matplotlib inline

我得到了这个:

AttributeError: 'NoneType' object has no attribute 'is_interactive'


In [1]: %matplotlib inline
---------------------------------------------------------------------------
UnknownBackend                            Traceback (most recent call last)
<ipython-input-1-2b1da000a957> in <module>()
----> 1 get_ipython().magic(u'matplotlib inline')

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2156         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2157         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2158         return self.run_line_magic(magic_name, magic_arg_s)
   2159 
   2160     #-------------------------------------------------------------------------

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2077                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2078             with self.builtin_trap:
-> 2079                 result = fn(*args,**kwargs)
   2080             return result
   2081 

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

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc 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/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
   2945                 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
   2946 
-> 2947         pt.activate_matplotlib(backend)
   2948         pt.configure_inline_support(self, backend)
   2949 

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in activate_matplotlib(backend)
    292     matplotlib.rcParams['backend'] = backend
    293 
--> 294     import matplotlib.pyplot
    295     matplotlib.pyplot.switch_backend(backend)
    296 

/Users/wonderful/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
   2510 # are no-ops and the registered function respect `mpl.is_interactive()`
   2511 # to determine if they should trigger a draw.
-> 2512 install_repl_displayhook()
   2513 
   2514 ################# REMAINING CONTENT GENERATED BY boilerplate.py ##############

/Users/wonderful/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in install_repl_displayhook()
    163             ipython_gui_name = backend2gui.get(get_backend())
    164             if ipython_gui_name:
--> 165                 ip.enable_gui(ipython_gui_name)
    166         else:
    167             _INSTALL_FIG_OBSERVER = True

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyc in enable_gui(self, gui)
    450     def enable_gui(self, gui=None):
    451         if gui:
--> 452             self._inputhook = get_inputhook_func(gui)
    453         else:
    454             self._inputhook = None

/Users/wonderful/anaconda/lib/python2.7/site-packages/IPython/terminal/pt_inputhooks/__init__.pyc in get_inputhook_func(gui)
     36 
     37     if gui not in backends:
---> 38         raise UnknownBackend(gui)
     39 
     40     if gui in aliases:

UnknownBackend: No event loop integration for 'inline'. Supported event loops are: qt, qt4, qt5, gtk, gtk2, gtk3, tk, wx, pyglet, glut, osx
Error in callback <function post_execute at 0x10ad69500> (for post_execute):
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/Users/wonderful/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py in post_execute()
    145 
    146             def post_execute():
--> 147                 if matplotlib.is_interactive():
    148                     draw_all()
    149 

AttributeError: 'NoneType' object has no attribute 'is_interactive'

1 个答案:

答案 0 :(得分:0)

对我来说,

  

pip install jupyter_console

然后

  

ipython控制台(&#39; jupyter console&#39;推荐)

     

在[1]中:%matplotlib内联

工作正常。

  

ipython console --matplotlib inline

会引发错误:

  

无法识别的旗帜:&#39; - matplotlib&#39;