0

I recently updated my Ubuntu to 18.04 and now when using Python (2.7) I cannot import matplotlib anymore. Error when importing:

>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/lib/python2.7/site-packages/matplotlib/__init__.py", line 131, in <module>
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "~/.local/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "~/.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

I installed matplotlib via

pip install --user matplotlib

Like matplotlib, functools_lru_cache-module is installed in

~/.local/lib/python2.7/site-packages

What am I missing here?

I tried uninstalling and reinstalling the "functools_lru_cache" module as suggested here: python 2.7 functools_lru_cache does not import although installed but that didn't help. Still same error.

ala
  • 224
  • 3
  • 16
  • Have you tried [this](https://stackoverflow.com/a/47317710/933770)? – Ali Momen Sani May 03 '18 at 10:29
  • Yes, I tried uninstalling and reinstalling "functools_lru_cache" via pip but I still get the same error – ala May 03 '18 at 10:52
  • What does `which pip` print? – Ali Momen Sani May 03 '18 at 11:03
  • There are several answers in that linked question. Which one did you try? – ImportanceOfBeingErnest May 03 '18 at 11:24
  • `which pip` prints `~/.local/bin/pip` – ala May 03 '18 at 11:36
  • @ImportanceOfBeingErnest I tried removing matplotlib and reinstalled it in Version 2.0.2. That fixed it for me. I will mark this question as answered/duplicate. – ala May 03 '18 at 11:42
  • Possible duplicate of [python 2.7 functools\_lru\_cache does not import although installed](https://stackoverflow.com/questions/47179433/python-2-7-functools-lru-cache-does-not-import-although-installed) – ala May 03 '18 at 11:47
  • Well that shouldn't be the solution. If there is something wrong with matplotlib 2.2.2 then it would need to be fixed. But as it stands it's not clear if there really is a problem. I would rather think that it has to do with different versions of python or pip being used. – ImportanceOfBeingErnest May 03 '18 at 11:49

1 Answers1

0

Uninstalling matplotlib via pip and installing an older version (2.0.2) fixed this for me. See: https://stackoverflow.com/a/49335954/1627966

ala
  • 224
  • 3
  • 16