Python matplotlib - ImportError: 找不到模块名为 functools_lru_cache。

我已经使用pip为Python安装了matplotlib,安装过程没有出现任何错误。然而,当我尝试导入它时,却遇到了这个错误:
import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rishabh/.local/lib/python2.7/site-packages/matplotlib/__init__.py", line 131, in <module>
    from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/home/rishabh/.local/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/home/rishabh/.local/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 28, in <module>
    from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache

1"functools_lru_cache.py":安装 python-backports.functools-lru-cache。链接:https://packages.ubuntu.com/search?keywords=python-backports.functools-lru-cache&searchon=names - Knud Larsen
2个回答

试试这个,我今天早上也遇到了同样的问题。
sudo apt-get install python-matplotlib

我也在使用Python3.7,在安装了一些模块之后稍晚开始运行。
pip3 install matplotlib

我现在可以导入matplotlib了。

先卸载
pip uninstall backports.functools_lru_cache

然后重新安装它
pip install backports.functools_lru_cache

就像在这个答案中所描述的一样