Recently, my code involving matplotlib.pyplot suddenly stopped working on all my machines (Ubuntu 22.04 LTS). I tried a simple import and got the following error:
$ python
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.10/dist-packages/matplotlib/pyplot.py", line 66, in <module>
from matplotlib.figure import Figure, FigureBase, figaspect
File "/usr/local/lib/python3.10/dist-packages/matplotlib/figure.py", line 43, in <module>
from matplotlib import _blocking_input, backend_bases, _docstring, projections
File "/usr/local/lib/python3.10/dist-packages/matplotlib/projections/__init__.py", line 58, in <module>
from mpl_toolkits.mplot3d import Axes3D
File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py", line 1, in <module>
from .axes3d import Axes3D
File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/axes3d.py", line 23, in <module>
from matplotlib import _api, cbook, docstring, _preprocess_data
ImportError: cannot import name 'docstring' from 'matplotlib' (/usr/local/lib/python3.10/dist-packages/matplotlib/__init__.py)
I am not sure what caused the problem, and how to diagnose or fix it. The matplotlib package is installed using pip as root, as I need it to be available to all users by default.
Has anyone encountered a similar issue and know how to fix it?