python 2.7 functools_lru_cache虽然已安装,但不导入

2024-05-23 23:16:48 发布

您现在位置:Python中文网/ 问答频道 /正文

当我尝试导入matplotlib时,我得到一个错误

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

后端口本身正确导入。当我尝试通过

sudo pip install backports.functools_lru_cache

我得到消息说

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

不过,当我试图

import backports.functools_lru_cache

我得到消息说

ImportError: No module named functools_lru_cache

系统信息 乌班图16 Python2.7.12 Pip 9.0.1点


Tags: inimportcachematplotliblibpackagesusrlocal
3条回答

如果有人仍然有这个问题,并且重新安装backports.functools_lru_cache在他的情况下不起作用,就像在我的情况下一样,那么安装旧版本的matplotlib可能会起作用。例如:

pip install matplotlib==2.0.2

版本2.2.0出现问题,我切换到2.0.2,它现在正在工作。我没有检查其他版本。

使用以下命令安装箭头:

pip install arrow==0.12.0 

帮我解决了这个问题

我也有同样的问题,但我解决了。

先卸载

pip uninstall backports.functools_lru_cache

然后重新安装。

pip install backports.functools_lru_cache

现在我可以导入matplotlib了。希望这有帮助。

相关问题 更多 >