无法从 PIL 导入图像

时间:2021-04-25 14:48:28

标签: python matplotlib image-processing data-science

我正在尝试使用 matplotlib,但是当我运行 python3.9 -m matplotlib 时出现此错误:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/maurothecreator/.local/lib/python3.9/site-packages/matplotlib/__init__.py", line 107, in <module>
    from . import _api, cbook, docstring, rcsetup
  File "/home/maurothecreator/.local/lib/python3.9/site-packages/matplotlib/rcsetup.py", line 24, in <module>
    from matplotlib import _api, animation, cbook
  File "/home/maurothecreator/.local/lib/python3.9/site-packages/matplotlib/animation.py", line 34, in <module>
    from PIL import Image
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 69, in <module>
    from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)

好的,我尝试检查 PIL,当我运行 python3.9 -m PIL 时,我得到几乎相同的错误,说 python 无法从 PIL 导入 _imaging,为什么?

我的机器上安装了两个 python3.xx 版本,python3.8.5 和 python3.9.4,运行 python3.8 我使用 python3,运行 python3.9 我使用 python3.9,当我尝试 python3 -m PIL 我收到一条消息:

--------------------------------------------------------------------
Pillow 7.0.0
Python 3.8.5 (default, Jan 27 2021, 15:41:15)
       [GCC 9.3.0]
--------------------------------------------------------------------
Python modules loaded from /usr/lib/python3/dist-packages/PIL
Binary modules loaded from /usr/lib/python3/dist-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok
--- TKINTER support ok
[...]

注意:这是一个非常重要的信息,这就是我放 [...] 的原因,但这不是信息的一部分

那么,为什么会发生这种情况?我该如何解决?

0 个答案:

没有答案