python 2.7 functools_lru_cache does not import alt

2019-01-14 15:40发布

When I try to import matplotlib I get an error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/__init__.py", line 128, in <module>
  from matplotlib.rcsetup import defaultParams, validate_backend, cycler
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/rcsetup.py", line 29, in <module>
    from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/fontconfig_pattern.py", line 32, in <module>
    from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache

backports itself imports properly. When I try to install functools manually via

sudo pip install backports.functools_lru_cache

I get info that

Requirement already satisfied: backports.functools_lru_cache in /usr/local/lib/python2.7/dist-packages

Nevertheless when i try to

import backports.functools_lru_cache

I get info that

ImportError: No module named functools_lru_cache

System info Ubuntu 16 Python 2.7.12 Pip 9.0.1

10条回答
Root(大扎)
2楼-- · 2019-01-14 16:02

this worked for me

from backports.functools_lru_cache import lru_cache
查看更多
冷血范
3楼-- · 2019-01-14 16:05

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

查看更多
欢心
4楼-- · 2019-01-14 16:12

I had the same problem but I fixed it.

Uninstall first

pip uninstall backports.functools_lru_cache

and then re-install it.

pip install backports.functools_lru_cache

Now I'm able to import matplotlib. Hope this helps.

查看更多
做个烂人
5楼-- · 2019-01-14 16:12

Install arrow using:

pip install arrow==0.12.0 

fixed this issue for me

查看更多
登录 后发表回答