Matplotlib import error : libwebp.so.6: cannot open shared object file: No such file or directory

I had asked this on SO but there was no reply so am here with the same problem.

I have installed matplotlib via pip3 in venv. After importing I get the error as below. Have changed the directory long path to …PATH.

>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "...PATH/lib/python3.11/site-packages/matplotlib/__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "...PATH/lib/python3.11/site-packages/matplotlib/rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "...PATH/lib/python3.11/site-packages/matplotlib/colors.py", line 51, in <module>
from PIL import Image
File "...PATH/lib/python3.11/site-packages/PIL/Image.py", line 103, in <module>
from . import _imaging as core
ImportError: libwebp.so.6: cannot open shared object file: No such file or directory

At pillow website I found that

Pillow >= 2.1.0 no longer supports import _imaging. Please use from PIL.Image import core as _imaging instead.

I am using pillow 9.4.0. And the last line of matplotlib error says that it is importing _imaging, which is no more valid in pillow. Matplotlib version is 3.6.3.

For the missing shared library (libwebp), being complained in the error, I have verified that it is already installed via dev package.

That use of _imaging is in Pillow itself; it can do whatever it likes internally. There is nothing here about Matplotlib.