我收到此错误“设置Matplotlib后端时出现以下错误!”打开Spyder时

时间:2019-10-06 19:19:29

标签: python matplotlib anaconda importerror

所以我刚刚重新安装了Anaconda,设置了我的环境,打开了Spyder并收到此错误消息:

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

Traceback (most recent call last):
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\spyder_kernels\console\kernel.py", line 477, in _set_mpl_backend
    get_ipython().run_line_magic(magic, backend)
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\IPython\core\interactiveshell.py", line 2314, in run_line_magic
    result = fn(*args, **kwargs)
  File "<C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\decorator.py:decorator-gen-109>", line 2, in matplotlib
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\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\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\IPython\core\interactiveshell.py", line 3414, in enable_matplotlib
    pt.activate_matplotlib(backend)
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\IPython\core\pylabtools.py", line 313, in activate_matplotlib
    import matplotlib.pyplot
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\matplotlib\pyplot.py", line 2355, in <module>
    switch_backend(rcParams["backend"])
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\matplotlib\pyplot.py", line 221, in switch_backend
    backend_mod = importlib.import_module(backend_name)
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\ipykernel\pylab\backend_inline.py", line 9, in <module>
    from matplotlib.backends.backend_agg import new_figure_manager, FigureCanvasAgg # analysis: ignore
  File "C:\Users\Julian\Anaconda3\envs\PythonGPU\lib\site-packages\matplotlib\backends\backend_agg.py", line 45, in <module>
    from PIL import Image
  File "C:\Users\Julian\AppData\Roaming\Python\Python37\site-packages\PIL\Image.py", line 64, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\Julian\AppData\Roaming\Python\Python37\site-packages\PIL\__init__.py)

2 个答案:

答案 0 :(得分:0)

是的,我也面临着同样的问题。

尝试重新安装软件包:

对于 Pip用户

pip uninstall matplotlib

对于 Pip3用户

pip3 uninstall matplotlib

重新安装:

pip install matplotlib
pip3 install matplotlib

答案 1 :(得分:0)

这刚好发生在我身上,原来是我在工具>首选项>终端ipython>图形>图形输出> Gtk3中修改了

将其更改为自动或其他,它对我有用