Skip to content

[Bug]: "import matplotlib.pyplot" gives ModuleNotFoundError #24454

@j1642

Description

@j1642

Bug summary

import matplotlib.pyplot returns ModuleNotFoundError: No module named 'importlib_resources' on Matplotlib version 8d2d4c2.

Can anyone reproduce this?

Code for reproduction

import matplotlib.pyplot as plt

Actual outcome

ModuleNotFoundError                       Traceback (most recent call last)
Cell In [3], line 1
----> 1 import matplotlib.pyplot as plt

File ~/Python/mpl/matplotlib/lib/matplotlib/pyplot.py:55
     53 import matplotlib.image
     54 from matplotlib import _api
---> 55 from matplotlib import rcsetup, style
     56 from matplotlib import _pylab_helpers, interactive
     57 from matplotlib import cbook

File ~/Python/mpl/matplotlib/lib/matplotlib/style/__init__.py:1
----> 1 from .core import available, context, library, reload_library, use
      4 __all__ = ["available", "context", "library", "reload_library", "use"]

File ~/Python/mpl/matplotlib/lib/matplotlib/style/core.py:26
     22     import importlib.resources as importlib_resources
     23 else:
     24     # Even though Py3.9 has importlib.resources, it doesn't properly handle
     25     # modules added in sys.path.
---> 26     import importlib_resources
     28 import matplotlib as mpl
     29 from matplotlib import _api, _docstring, _rc_params_in_file, rcParamsDefault

ModuleNotFoundError: No module named 'importlib_resources'

Expected outcome

Successful import.

Additional information

The error is from lib/matplotlib/style/core.py.

Locally on Python 3.9.7, I can fix the error by changing the operator on line 21 from >= to <=. I don't know if that will help other python versions.

Operating system

Ubuntu

Matplotlib Version

commit 8d2d4c2

Matplotlib Backend

No response

Python version

3.9.7

Jupyter version

No response

Installation

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions