When I try to import matplotlib I get an error
Traceback (most recent call last):
File \"\", line 1, in
File \"/usr/local/lib
This worked for me. Ubuntu 18.04.
sudo pip2 uninstall backports.functools-lru-cache
sudo apt install python-backports.functools-lru-cache
I had the same problem and my solution was;
Download whl file from https://pypi.python.org/pypi/backports.functools_lru_cache/1.3
pip install
I solved my problem by removing the excessive matplotlib packages. I found out that when importing matplotlib it was attempting to import backports.functools_lru_cache
and there it was throwing the Importerror
.
I realized that I had different matplotlib packages in many locations:
/usr/lib/python2.7/dist-packages/matplotlib/
/usr/lib/python2.7/site-packages/matplotlib/
I removed the site-packages one. I left the dist-packages one intact.
Then I ran the following commands in python:
matplotlib.get_configdir()
matplotlib.get_cachedir()
and I removed the matplotlib packages in the output paths of these commands.
Then I removed the matplotlib in my virtualenvironment:
mv /home/username/virtualenvironment/lib/python2.7/matplotlib* /tmp
Finally I removed the one in the .local folder:
mv /home/username/.local/lib/python2.7/matplotlib* /tmp
Now importing matplotlib works fine. So when I run in python:
matplotlib.__file__
it returns
'/usr/lib/python2.7/dist-packages/matplotlib/__init__.pyc'
Now it does not throw error anymore when import backports.functools_lru_cache
Following from Aditya Jain's answer,
[python -m] pip uninstall backports.functools_lru_cache
[python -m] pip install backports.functools_lru_cache==1.2.1
which will avoid installing arrow
merely to downgrade functools_lru_cache
.
You have to check what is the import path of backports package:
import backports
print('Backports Path: {0}'.format(backports.__path__))
1. The import path is the main python path ( the case of Matimath's question)
pip uninstall backports.functools_lru_cache (this will uninstall it from /usr/local/) pip install backports.functools_lru_cache
2. The import path is the local usr dir (~/.local/, or %APPDATA%\Python for windows)
pip uninstall backports.functools_lru_cache pip install --user backports.functools_lru_cache
Use pip2 command for python2.
The reason for this inconsistency is that the import path of backports package might have been changed during another module/package installation (eg. from backports.configparser module) - see here for more details: https://bugs.python.org/issue31741
this worked for me
from backports.functools_lru_cache import lru_cache