Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ImportError: No module named functools_lru_cache #9344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Albert-Z-Guo opened this issue Oct 10, 2017 · 31 comments
Closed

ImportError: No module named functools_lru_cache #9344

Albert-Z-Guo opened this issue Oct 10, 2017 · 31 comments

Comments

@Albert-Z-Guo
Copy link

Albert-Z-Guo commented Oct 10, 2017

Bug report

Bug summary

upgraded matplotlib using MacPorts and found out that matplotlib now can't be imported

tried uninstall and reinstall matplotlib using MacPorts but the problem still exists

Code for reproduction

import matplotlib

Actual outcome

Traceback (most recent call last):
  File "/Users/Albert_Guo/Desktop/test_code.py", line 1, in <module>
    import matplotlib
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 128, in <module>
    from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py", line 32, in <module>
    from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache

Expected outcome

Matplotlib version

  • Operating system: macOS Sierra Version: 10.12.6
  • Matplotlib version: py27-matplotlib @2.1.0_1 (installed by MacPorts)
  • Matplotlib backend (print(matplotlib.get_backend())): can't print anything because matplotlib can't be imported at the first place
  • Python version: python27 @2.7.14 (installed by MacPorts)
  • Jupyter version (if applicable): py27-jupyter @1.0.0_1 (installed by MacPorts)
  • Other libraries: py27-backports @1.0_0 (installed by MacPorts)
@WeatherGod
Copy link
Member

WeatherGod commented Oct 10, 2017 via email

@Albert-Z-Guo
Copy link
Author

Albert-Z-Guo commented Oct 10, 2017

backports? Yes, I do have it. But the problem still exists.

@WeatherGod
Copy link
Member

WeatherGod commented Oct 10, 2017 via email

@Albert-Z-Guo
Copy link
Author

I solved this problem. Thanks for the quick help @WeatherGod!

I need to manually install another package named "py27-backports-functools_lru_cache" through MacPorts.

I guess I shall move to Python 3 now. Python 2.7 seems to have more and more legacy compatibility problems these days.

@WeatherGod
Copy link
Member

WeatherGod commented Oct 10, 2017 via email

@paulbrodersen
Copy link

Can we re-open this issue, please? The problem re-surfaces (at least for me) when I pip install matplotlib 2.1.0 in a clean virtualenv. Regression to matplotlib 2.0.2 solves the problem. Ubuntu 17.04, virtualenv with python 2.7.13.

@tacaswell
Copy link
Member

@paulbrodersen What version of pip are you using? Starting from an empty venv works correctly for me:

12:23 $ virtualenv2 /tmp/lpy
New python executable in /tmp/lpy/bin/python2
Also creating executable in /tmp/lpy/bin/python
Installing setuptools, pip, wheel...done.
✔ ~ 
12:25 $ source /tmp/lpy/bin/activate
(lpy) ✔ ~ 
12:25 $ pip install matplotlib
Collecting matplotlib
  Downloading matplotlib-2.1.0-cp27-cp27mu-manylinux1_x86_64.whl (14.9MB)
    100% |████████████████████████████████| 14.9MB 73kB/s 
Collecting python-dateutil>=2.0 (from matplotlib)
  Using cached python_dateutil-2.6.1-py2.py3-none-any.whl
Collecting cycler>=0.10 (from matplotlib)
  Using cached cycler-0.10.0-py2.py3-none-any.whl
Collecting subprocess32 (from matplotlib)
Collecting pytz (from matplotlib)
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
    100% |████████████████████████████████| 512kB 1.7MB/s 
Collecting six>=1.10 (from matplotlib)                                                                                                                                                                                                
  Downloading six-1.11.0-py2.py3-none-any.whl                                                                                                                                                                                         
Collecting backports.functools-lru-cache (from matplotlib)                                                                                                                                                                            
  Using cached backports.functools_lru_cache-1.4-py2.py3-none-any.whl                                                                                                                                                                 
Collecting numpy>=1.7.1 (from matplotlib)                                                                                                                                                                                             
  Downloading numpy-1.13.3-cp27-cp27mu-manylinux1_x86_64.whl (16.6MB)                                                                                                                                                                 
    100% |████████████████████████████████| 16.7MB 66kB/s 
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)                                                                                                                                                                 
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl                                                                                                                                                                                   
Installing collected packages: six, python-dateutil, cycler, subprocess32, pytz, backports.functools-lru-cache, numpy, pyparsing, matplotlib                                                                                          
Successfully installed backports.functools-lru-cache-1.4 cycler-0.10.0 matplotlib-2.1.0 numpy-1.13.3 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0 subprocess32-3.2.7                                                  
(lpy) ✔ ~                                                                                                                                                                                                                             
12:25 $ python                                                                                                                                                                                                                        
Python 2.7.14 (default, Sep 20 2017, 01:25:59)                                                                                                                                                                                        
[GCC 7.2.0] on linux2                                                                                                                                                                                                                 
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                                                                
>>> import matplotlib                                                                                                                                                                                                                 
>>> import matplotlib.pyplot as plt                                                                                                                                                                                                   
>>>                      

Can you post your install log?

@paulbrodersen
Copy link

This is getting more and more mysterious: backports.functools-lru-cache is clearly being downloaded and installed, but somehow it ends up not being on the path?!

> pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Setting up fresh virtualenv, installing matplotlib, ignoring cache:

paul@paul-XPS-15-9560:~⟫ mkvirtualenv test_matplotlib_install
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/paul/.virtualenvs/test_matplotlib_install/bin/python2
Also creating executable in /home/paul/.virtualenvs/test_matplotlib_install/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
(test_matplotlib_install) paul@paul-XPS-15-9560:~⟫ pip install --no-cache-dir matplotlib
Collecting matplotlib
  Downloading matplotlib-2.1.0-cp27-cp27mu-manylinux1_x86_64.whl (14.9MB)
    100% |████████████████████████████████| 14.9MB 9.3MB/s
Collecting backports.functools-lru-cache (from matplotlib)
  Downloading backports.functools_lru_cache-1.4-py2.py3-none-any.whl
Collecting python-dateutil>=2.0 (from matplotlib)
  Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 7.3MB/s
Collecting numpy>=1.7.1 (from matplotlib)
  Downloading numpy-1.13.3-cp27-cp27mu-manylinux1_x86_64.whl (16.6MB)
    100% |████████████████████████████████| 16.7MB 7.5MB/s
Collecting cycler>=0.10 (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib)
  Downloading pyparsing-2.2.0-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 10.2MB/s
Collecting six>=1.10 (from matplotlib)
  Downloading six-1.11.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib)
  Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
    100% |████████████████████████████████| 512kB 9.5MB/s
Collecting subprocess32 (from matplotlib)
  Downloading subprocess32-3.2.7.tar.gz (54kB)
    100% |████████████████████████████████| 61kB 17.6MB/s
Installing collected packages: backports.functools-lru-cache, six, python-dateutil, numpy, cycler, pyparsing, pytz, subprocess32, matplotlib
  Running setup.py install for subprocess32 ... done
Successfully installed backports.functools-lru-cache-1.4 cycler-0.10.0 matplotlib-2.1.0 numpy-1.13.3 pyparsing-2.2.0 python-dateutil-2.6.1 pytz-2017.3 six-1.11.0 subprocess32-3.2.7

ImportError:

(test_matplotlib_install) paul@paul-XPS-15-9560:~⟫ ipython
/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py:726: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5cdaae59dc80> in <module>()
----> 1 import numpy as np; import matplotlib.pyplot as plt

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
    126     _backports, mplDeprecation, dedent, get_label, sanitize_sequence)
    127 from matplotlib.compat import subprocess
--> 128 from matplotlib.rcsetup import defaultParams, validate_backend, cycler
    129
    130 import numpy

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/rcsetup.py in <module>()
     27
     28 from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper
---> 29 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
     30 from matplotlib.colors import is_color_like
     31

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py in <module>()
     30     from functools import lru_cache
     31 except ImportError:
---> 32     from backports.functools_lru_cache import lru_cache
     33
     34 family_punc = r'\\\-:,'

ImportError: No module named functools_lru_cache

@tacaswell
Copy link
Member

It looks like you are pulling IPython from the system level but still importing some things from the venv.

Also check what is in sys.path. I suspect you have both the system python paths and the venv paths in there.

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

The first line of your output indicates what the problem likely is and how to fix it ;-)

@paulbrodersen
Copy link

Installing ipython inside the venv has no effect:

(test_matplotlib_install) paul@paul-XPS-15-9560:~⟫ pip install --no-cache-dir ipython                                                                                                                              
Collecting ipython                                                                                                                                                                                                 
  Downloading ipython-5.5.0-py2-none-any.whl (758kB)                                                                                                                                                               
    100% |████████████████████████████████| 768kB 11.7MB/s                                                                                                                                                         
Requirement already satisfied: setuptools>=18.5 in ./.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages (from ipython)                                                                               
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython)                                                                                                                              
  Downloading backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl                                                                                                                                        
Collecting pickleshare (from ipython)                                                                                                                                                                              
  Downloading pickleshare-0.7.4-py2.py3-none-any.whl                                                                                                                                                               
Collecting simplegeneric>0.8 (from ipython)                                                                                                                                                                        
  Downloading simplegeneric-0.8.1.zip                                                                                                                                                                              
Collecting decorator (from ipython)                                                                                                                                                                                
  Downloading decorator-4.1.2-py2.py3-none-any.whl                                                                                                                                                                 
Collecting prompt-toolkit<2.0.0,>=1.0.4 (from ipython)                                                                                                                                                             
  Downloading prompt_toolkit-1.0.15-py2-none-any.whl (247kB)                                                                                                                                                       
    100% |████████████████████████████████| 256kB 9.9MB/s                                                                                                                                                          
Collecting pexpect; sys_platform != "win32" (from ipython)                                                                                                                                                         
  Downloading pexpect-4.3.0-py2.py3-none-any.whl (55kB)                                                                                                                                                            
    100% |████████████████████████████████| 61kB 20.5MB/s                                                                                                                                                          
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython)                                                                                                                             
  Downloading pathlib2-2.3.0-py2.py3-none-any.whl                                                                                                                                                                  
Collecting pygments (from ipython)                                                                                                                                                                                 
  Downloading Pygments-2.2.0-py2.py3-none-any.whl (841kB)                                                                                                                                                          
    100% |████████████████████████████████| 849kB 9.0MB/s                                                                                                                                                          
Collecting traitlets>=4.2 (from ipython)                                                                                                                                                                           
  Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |████████████████████████████████| 81kB 11.4MB/s
Requirement already satisfied: six>=1.9.0 in ./.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
  Downloading wcwidth-0.1.7-py2.py3-none-any.whl
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
  Downloading ptyprocess-0.5.2-py2.py3-none-any.whl
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython)
  Downloading scandir-1.6.tar.gz
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting enum34; python_version == "2.7" (from traitlets>=4.2->ipython)
  Downloading enum34-1.1.6-py2-none-any.whl
Installing collected packages: backports.shutil-get-terminal-size, scandir, pathlib2, pickleshare, simplegeneric, decorator, wcwidth, prompt-toolkit, ptyprocess, pexpect, pygments, ipython-genutils, enum34, tra$tlets, ipython
  Running setup.py install for scandir ... done
  Running setup.py install for simplegeneric ... done
Successfully installed backports.shutil-get-terminal-size-1.0.0 decorator-4.1.2 enum34-1.1.6 ipython-5.5.0 ipython-genutils-0.2.0 pathlib2-2.3.0 pexpect-4.3.0 pickleshare-0.7.4 prompt-toolkit-1.0.15 ptyprocess-$.5.2 pygments-2.2.0 scandir-1.6 simplegeneric-0.8.1 traitlets-4.3.2 wcwidth-0.1.7

ImportError:

(test_matplotlib_install) paul@paul-XPS-15-9560:~⟫ ipython
/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py:726: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
  warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 2.7.13 (default, Jan 19 2017, 14:48:08)
Type "copyright", "credits" or "license" for more information.

IPython 5.4.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-5cdaae59dc80> in <module>()
----> 1 import numpy as np; import matplotlib.pyplot as plt

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
    126     _backports, mplDeprecation, dedent, get_label, sanitize_sequence)
    127 from matplotlib.compat import subprocess
--> 128 from matplotlib.rcsetup import defaultParams, validate_backend, cycler
    129
    130 import numpy

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/rcsetup.py in <module>()
     27
     28 from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper
---> 29 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
     30 from matplotlib.colors import is_color_like
     31

/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages/matplotlib/fontconfig_pattern.py in <module>()
     30     from functools import lru_cache
     31 except ImportError:
---> 32     from backports.functools_lru_cache import lru_cache
     33
     34 family_punc = r'\\\-:,'

ImportError: No module named functools_lru_cache

@paulbrodersen
Copy link

paulbrodersen commented Nov 24, 2017

I do have weird stuff in my sys.path, and I am unsure how that stuff got there as I just created the venv. However, as far as I can see, site-packages are only imported from .virtualenvs/test_matplotlib_install/lib/python2.7/site-packages, so it seems to me that I am not importing another matplotlib version from somewhere else.

In [3]: sys.path
Out[3]: 
['/home/paul/.virtualenvs/test_matplotlib_install/lib/python2.7/site-packages',
 '',
 '/usr/local/bin',
 '/home/paul',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/wx-3.0-gtk2',
 '/usr/local/lib/python2.7/dist-packages/IPython/extensions',
 '/home/paul/.ipython']

@paulbrodersen
Copy link

@jklymak Which line are you referring to?

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py:726: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.

So the ipython you are calling is not in your virtualenv. In fact, as you can clearly see above, the versions are diferent; 5.4.1 is what you call, and 5.5.0 is what you installed.

Unless you like banging your head against a wall or have some compelling use-case that precludes it, I strongly suggest using anaconda. I'm sure all that /usr/lib/ stuff is whats causing you grief.

@paulbrodersen
Copy link

paulbrodersen commented Nov 24, 2017

Ok. ipython does indeed seem to be the problem. I also noticed that ipython was still complaining about not being installed in the venv when I clearly had just installed it. That lead me to this issue, which suggests running hash -r to clear cached paths. Apparently, you run into this problem if you install ipython inside the venv after having run ipython beforehand. The ipython path is still cached and hence pointing to the previous ipython version. I still have no idea why that should affect which matplotlib version is being loaded, but it clearly does as import matplotlib.pyplot executes without error after clearing the cache.

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

Its possible (likely?) hash -r also reset other libraries.

@paulbrodersen
Copy link

It seems unlikely that I would have had a matplotlib path already cached. I opened a new shell before initializing the venv. In my window manager (byobu) the hash table is empty when I initialize a new shell. Anyway, I am fairly happy now (albeit still confused). Thanks for all the help!

@WeatherGod
Copy link
Member

WeatherGod commented Nov 27, 2017 via email

@skyson
Copy link

skyson commented Feb 6, 2018

come across with problem, after uninstall the matplotlib and install the privious version 2.0.2, the problem is solved

@nadnerbity
Copy link

nadnerbity commented May 24, 2018

Same as above: #9344 but I don't have anything funny in my path, I am not using a virtual environment and have installed everything using apt (I'm on Ubuntu 18.04). If I go back to matplotlib 2.0.2 using pip then it works, so I'm going with that for now, but I'd rather not use a billion installers.

I'm having this problem with matplotlib 2.1+ too, but only with Python:

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python2.7/site-packages/matplotlib/__init__.py", line 131, in <module>
    from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/home/user/.local/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/home/user/.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

When I use iPython everything is peachy:


Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import matplotlib

I am not at all sure what is causing this. I suspect there is some local vs system library thing going on. How do I fix this?

Update:
If I import pip before attempting to import matplotlib, it works in python.

>>> from backports.functools_lru_cache import lru_cache
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named functools_lru_cache
>>> import pip
>>> from backports.functools_lru_cache import lru_cache

It looks like importing pip changes at least the sys.path but I can't tell why what it is doing matters and how that relates to ipython.

Update #2:
I suspect no one is reading this but I figured out what is going on. Rather why ipython works and python doesn't. It is a path issue but I am not sure why it is a path issue. I had a stack exchange Q up too, which can be found here: https://stackoverflow.com/questions/50538327/python-matplotlib-loads-using-ipython-but-not-using-python.

The problem appears to be a path problem I am not sure how to solve. I use apt on Ubuntu 18.04 to install system modules into /usr/lib/python2.7/dist-packages/. This directory is where backports.functools_lru_cache lives. I also have some compiled modules installed in /usr/local/lib/python2.7/dist-packages/ where there is a backports module WITHOUT functools_lru_cache. The problem is that python is not following the system path and only seems to be looking in /usr/local/lib/python2.7/dist-packages/ for backports. However, ipython looks in both which is why ipython was working while python was not.

python:

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/home/brendan/.local/lib/python2.7/site-packages', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/gtk-2.0']
>>> import backports
>>> backports.__path__
['/usr/local/lib/python2.7/dist-packages/backports']

ipython:

Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: sys.path
Out[1]: 
['',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/brendan/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/gtk-2.0']

In [2]: import backports

In [3]: backports.__path__
Out[3]: 
['/usr/local/lib/python2.7/dist-packages/backports',
 '/usr/lib/python2.7/dist-packages/backports']

Solution:

To solve the problem I manually copied functools_lru_cache.py from /usr/lib/python2.7/dist-packages/backports/ to /usr/local/lib/python2.7/dist-packages/backports/. Now I can run matplotlib 2.2.2 no problem in python and ipython.

It isn't clear to my why python and ipython are ignoring my request to reorder the path. My suspicion is that it has to do with backports being "built-in" now. I have another machine running 2.7.12 and it doesn't have this problem and backports isn't built in. ipython works because it looks in two places.

@andrewyong87
Copy link

@nadnerbity you idea is useful to me, I met the same error, both the os version and the dependencies packages are same with your's. Follow your way I fixed the error.

@solatale
Copy link

solatale commented Sep 5, 2018

In my case, I pip installed the package named "backports-functools_lru_cache" for MacOSX.

@Borda
Copy link
Contributor

Borda commented Jan 2, 2019

Uninstall first pip uninstall backports.functools_lru_cache
and then re-install it pip install backports.functools_lru_cache

https://stackoverflow.com/a/47317710/4521646

@ha7ilm
Copy link

ha7ilm commented Mar 4, 2019

I solved it by installing the following from the Ubuntu repos:

sudo apt install python-backports.functools-lru-cache

@rocchow
Copy link

rocchow commented Apr 22, 2019

I solved it by installing the following from the Ubuntu repos:

sudo apt install python-backports.functools-lru-cache

I updated to Ubuntu 19.04 and used this method to resolve.

@tacaswell
Copy link
Member

@sandrotosi This suggests that there is a bug in the py2 dependencies for the debian packaging?

@sandrotosi
Copy link
Contributor

@tacaswell it's highly unlikely something in Debian is not ok with dependencies, as there would be people screaming all over the place and this is the first time i heard about this :)

the OP is on Mac, and the 2 latest users look like they are using Ubuntu, which may have a more original way of handling dependencies due to their main/universe repos separations, but i cant comment on Ubuntu as i dont maintain the package there

let me know if i can help in any way tho

@tacaswell
Copy link
Member

Ah, sorry to bother you @sandrotosi , I thought the debian -> ubuntu pipeline was more direct.

https://bugs.launchpad.net/ubuntu/+source/matplotlib/+bug/1764823 For ubuntu it looks like there is an open issue about this problem (that is blamed an the python-backports.functools-lru-cache package missing a file!).

@sandrotosi
Copy link
Contributor

ah yeah, when i first introduce backports.funtools_lru_cache i had issues as well in defining the namespace backports in Debian, and had to fix a couple of other packages sharing that namespace to have them all cooperate

@aaronjohnsabu1999
Copy link

I solved it by installing the following from the Ubuntu repos:

sudo apt install python-backports.functools-lru-cache

This helped. Thanks!!!

@marwan2akram
Copy link

sudo apt install python-backports.functools-lru-cache

it worked with me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests