spyder控制台中的Matplotlib后端错误?

Posted

技术标签:

【中文标题】spyder控制台中的Matplotlib后端错误?【英文标题】:Matplotlib backend error in spyder console? 【发布时间】:2021-07-19 00:32:54 【问题描述】:

任何想法如何处理我的 spyder (5.0.0) 控制台中的以下错误?

Output from spyder call 'show_mpl_backend_errors':

=========================================================================
NOTE: The following error appeared when setting your Matplotlib backend!!
=========================================================================

Traceback (most recent call last):
  File "C:\Users\hana\anaconda3\lib\site-packages\spyder_kernels\console\kernel.py", line 735, in _set_mpl_backend
    get_ipython().run_line_magic(magic, backend)
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\IPython\core\interactiveshell.py", line 2326, in run_line_magic
    result = fn(*args, **kwargs)
  File "<decorator-gen-109>", line 2, in matplotlib
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
    gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\IPython\core\interactiveshell.py", line 3431, in enable_matplotlib
    pt.activate_matplotlib(backend)
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\IPython\core\pylabtools.py", line 320, in activate_matplotlib
    from matplotlib import pyplot as plt
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 36, in <module>
    import matplotlib.colorbar
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\colorbar.py", line 44, in <module>
    import matplotlib.contour as contour
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\contour.py", line 17, in <module>
    import matplotlib.text as text
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\text.py", line 16, in <module>
    from .textpath import TextPath  # Unused, but imported by others.
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\textpath.py", line 11, in <module>
    from matplotlib.mathtext import MathTextParser
  File "C:\Users\hana\anaconda3\lib\site-packages\matplotlib\mathtext.py", line 27, in <module>
    from PIL import Image
  File "C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\PIL\Image.py", line 94, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\hana\AppData\Roaming\Python\Python38\site-packages\PIL\__init__.py)

我目前有matplotlib 3.3.4,尝试将设置从内联更改为自动并重新安装anaconda,但错误仍然存​​在:(

谢谢!

【问题讨论】:

【参考方案1】:

我再次卸载了 anaconda,然后从系统目录 (%appdata% & %programfiles%) 和 Windows 注册表中删除了所有剩余文件。

再次安装后,错误消失了。 :)

【讨论】:

这里是 Spyder 维护者)我很高兴你能够自己解决这个问题。下次请避免使用pip 安装包,并删除此目录`C:\Users\hana\AppData\Roaming\Python`(不需要卸载Anaconda)。

以上是关于spyder控制台中的Matplotlib后端错误?的主要内容,如果未能解决你的问题,请参考以下文章

在spyder下调用cerebro.plot()不显示图片问题

Mac 上的 Anaconda:无法将 Matplotlib 后端设置为 Agg

如何更改 matplotlib - spyder 中的默认绘图颜色? [复制]

Anaconda matplotlib 升级后 Spyder 停止工作

matplotlib 中的动画在 spyder 中不起作用

未找到 Matplotlib Qt5Agg 后端