4

I have installed matplotlib for Python using pip which was completed without error. Yet I get this error when I try to import it:

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
Byte Commander
  • 105,631
  • 46
  • 284
  • 425
r k
  • 41
  • 1
  • 1
  • 3
  • 1
    "functools_lru_cache.py" : Install `python-backports.functools-lru-cache` https://packages.ubuntu.com/search?keywords=python-backports.functools-lru-cache&searchon=names – Knud Larsen Jun 14 '18 at 15:29

2 Answers2

5

try this I had same problem this morning

sudo apt-get install python-matplotlib

I also am using python3.7 a little later after I installed a few modules. I ran.

pip3 install matplotlib

I can now import matplotlib.

trietend
  • 190
  • 10
plutesci
  • 341
  • 1
  • 2
  • 18
4

Uninstall first

pip uninstall backports.functools_lru_cache

and then re-install it

pip install backports.functools_lru_cache

like described in this answer.

zx485
  • 2,249
  • 11
  • 24
  • 34
Jirka
  • 141
  • 4