我正在尝试在Jupyter中使用'Qt5Agg'matplotlib后端,但是当我运行%matplotlib qt
时,出现以下错误:
ImportError Traceback (most recent call last)
<ipython-input-1-f6a92ad1c7f8> in <module>
----> 1 get_ipython().run_line_magic('matplotlib', 'qt')
2 import numpy as np
3 from scipy.integrate import odeint
4 import matplotlib.pyplot as plt
5 from mpl_toolkits.mplot3d import Axes3D
~/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line, _stack_depth)
2312 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2313 with self.builtin_trap:
-> 2314 result = fn(*args, **kwargs)
2315 return result
2316
</home/cs/.local/lib/python3.5/site-packages/decorator.py:decorator-gen-108> in matplotlib(self, line)
~/.local/lib/python3.5/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
185 # but it's overkill for just that one bit of state.
186 def magic_deco(arg):
--> 187 call = lambda f, *a, **k: f(*a, **k)
188
189 if callable(arg):
~/.local/lib/python3.5/site-packages/IPython/core/magics/pylab.py in matplotlib(self, line)
97 print("Available matplotlib backends: %s" % backends_list)
98 else:
---> 99 gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
100 self._show_matplotlib_backend(args.gui, backend)
101
~/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py in enable_matplotlib(self, gui)
3412 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
3413
-> 3414 pt.activate_matplotlib(backend)
3415 pt.configure_inline_support(self, backend)
3416
~/.local/lib/python3.5/site-packages/IPython/core/pylabtools.py in activate_matplotlib(backend)
312
313 import matplotlib.pyplot
--> 314 matplotlib.pyplot.switch_backend(backend)
315
316 # This must be imported last in the matplotlib series, after
~/.local/lib/python3.5/site-packages/matplotlib/pyplot.py in switch_backend(newbackend)
220 "Cannot load backend {!r} which requires the {!r} interactive "
221 "framework, as {!r} is currently running".format(
--> 222 newbackend, required_framework, current_framework))
223
224 rcParams['backend'] = rcParamsDefault['backend'] = newbackend
ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running
我尝试先运行:
import matplotlib
matplotlib.use('Qt5Agg')
但是,如果我再次运行%matplotlib qt
,则会遇到相同的错误。
如果我没有运行magic命令,并且绘制了一些东西,那么它什么也不会显示。