【问题标题】:import matplotlib.backends.backend_tkagg - ModuleNotFoundError: No module named 'PIL'导入 matplotlib.backends.backend_tkagg - ModuleNotFoundError:没有名为“PIL”的模块
【发布时间】:2020-08-21 07:15:38
【问题描述】:

我正在使用 python 3.8.5 并在 Windows 10 上运行。我试图在 Tkinter Gui 中插入一个绘图,但是当我导入 matplotlib.backends.backend_tkagg 时,它会引发如下所示的错误。 Mathplotlib 和 Tkinter 版本分别是最新版本 8.6 和 3.3.1。而且我还安装了“枕头”模块。

image showing the error

>>>import matplotlib.backends.backend_tkagg

这也是错误-

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 1, in <module>
    from . import _backend_tk
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 15, in <module>
    from matplotlib.backend_bases import (
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\backend_bases.py", line 45, in <module>
    from matplotlib import (
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\textpath.py", line 11, in <module>
    from matplotlib.mathtext import MathTextParser
  File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\matplotlib\mathtext.py", line 27, in <module>
    from PIL import Image
ModuleNotFoundError: No module named 'PIL'

【问题讨论】:

  • Pillow 安装了吗?如果没有,请使用“pip install Pillow”安装它并检查是否仍然出现错误。
  • @P.Leibner Pillow 已安装。我在帖子上写的。即使我安装了 Pillow,它也不起作用。
  • 也许你使用了错误版本的python作为你的解释器?
  • 不,我只安装了一个python版本,我什至没有使用虚拟环境来运行这段代码。

标签: python matplotlib tkinter python-imaging-library


【解决方案1】:

如果你使用 anaconda 试试

conda install pillow

如果你使用 pip 试试:

pip install Pillow

确保安装到正确的环境。然后导入应该可以工作了。

【讨论】:

  • 枕头可以自己导入吗?
  • 怎么样?我使用“py -m pip install枕头”命令安装。但它不起作用仍然会出错。
  • 试试你做的脚本from PIL import Image
猜你喜欢
  • 1970-01-01
  • 2021-05-16
  • 2019-04-12
  • 2021-04-02
  • 2020-02-25
  • 2021-12-14
  • 2022-01-07
  • 2020-03-11
  • 1970-01-01
相关资源
最近更新 更多