The Wayback Machine - https://web.archive.org/web/20250527172735/https://github.com/matplotlib/matplotlib/issues/21220
Skip to content

[Bug]: ImportError: cannot import name '_imaging' from 'PIL'  #21220

Closed
@RaulCPena

Description

@RaulCPena

Bug summary

trying to import matplotlib in the following ways

import matplotlib.pyplot as plt
from matplotlib import pyplot as plt

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib import pyplot as plt

Actual outcome

ImportError: cannot import name '_imaging' from 'PIL' (C:\Python\Python39\lib\site-packages\PIL\__init__.py)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
C:\Users\Name~1\AppData\Local\Temp/ipykernel_12196/1952718793.py in <module>
----> 1 import matplotlib

C:\Python\Python39\lib\site-packages\matplotlib\__init__.py in <module>
    105 # cbook must import matplotlib only within function
    106 # definitions, so it is safe to import from it here.
--> 107 from . import _api, cbook, docstring, rcsetup
    108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
    109 from matplotlib.cbook import mplDeprecation  # deprecated

C:\Python\Python39\lib\site-packages\matplotlib\rcsetup.py in <module>
     22 import numpy as np
     23 
---> 24 from matplotlib import _api, animation, cbook
     25 from matplotlib.cbook import ls_mapper
     26 from matplotlib.colors import Colormap, is_color_like

C:\Python\Python39\lib\site-packages\matplotlib\animation.py in <module>
     32 
     33 import numpy as np
---> 34 from PIL import Image
     35 
     36 import matplotlib as mpl

C:\Python\Python39\lib\site-packages\PIL\Image.py in <module>
    112     # Also note that Image.core is not a publicly documented interface,
    113     # and should be considered private and subject to change.
--> 114     from . import _imaging as core
    115 
    116     if __version__ != getattr(core, "PILLOW_VERSION", None):

ImportError: cannot import name '_imaging' from 'PIL' (C:\Python\Python39\lib\site-packages\PIL\__init__.py)

Expected outcome

I expected to be able to import matplotlib

Operating system

Windows 10 Enterprise

Matplotlib Version

3.4.3

Matplotlib Backend

No response

Python version

3.9.7

Jupyter version

7.0.5

Other libraries

No response

Installation

pip

Conda channel

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions