当我尝试使用python加载matplotlib时,我收到有关加载backports.functools_lru_cache模块的错误。当我尝试使用ipython加载matplotlib时,它加载就好了。
尽管我可以告诉ipython使用调用python使用的相同版本的python。我已经完成了python和ipython使用和卸载matplotlib和backports.functools_lru_cache的路径。我已经尝试过使用apt和pip重新安装,在尝试下一次尝试之前总是卸载之前的尝试。
我已经完成了一堆stackexchange解决方案并尝试了一些没有运气的github解决方案。我运行Ubuntu 18.04。
错误:
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 "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 127, in <module>
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
File "/usr/lib/python2.7/dist-packages/matplotlib/rcsetup.py", line 29, in <module>
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
File "/usr/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
我不会展示ipython,因为它加载得很好。
更新
如果我使用安装:
pip install matplotlib==2.0.2
matplotlib适用于python和ipython。
答案 0 :(得分:0)
问题似乎是路径问题我不知道如何解决。我在Ubuntu 18.04上使用apt将系统模块安装到/usr/lib/python2.7/dist-packages/中。此目录是backports.functools_lru_cache所在的目录。我还在/usr/local/lib/python2.7/dist-packages/中安装了一些已编译的模块,其中有一个没有functools_lru_cache的backports模块。问题是python不遵循系统路径,似乎只在/usr/local/lib/python2.7/dist-packages/中查找backports。但是,ipython看起来都是为什么ipython正在工作而python没有。
<强>蟒:强>
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']
<强> IPython的:强>
transitTransactions
<强>解决方案:强>
为了解决这个问题,我手动将functools_lru_cache.py从/usr/lib/python2.7/dist-packages/backports/复制到/usr/local/lib/python2.7/dist-packages/backports/。现在我可以在python和ipython中运行matplotlib 2.2.2没问题。
我要回答这个问题,因为我现在的问题围绕着python和路径。