问题描述
尝试运行此示例来测试matplotlib如何与Tkinter一起工作时,我出现错误:
While trying to run this example to test how matplotlib works with Tkinter, I am getting the error:
(env)fieldsofgold@fieldsofgold-VirtualBox:~/new$ python test.py
Traceback (most recent call last):
File "test.py", line 7, in <module>
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
File "/home/fieldsofgold/new/env/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 13, in <module>
import matplotlib.backends.tkagg as tkagg
File "/home/fieldsofgold/new/env/local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 7, in <module>
from matplotlib.backends import _tkagg
ImportError: cannot import name _tkagg
使用此处提供的解决方案,我尝试卸载matplotlib并使用以下命令安装tk和tk-dev软件包:
Using the solution provided here, I've tried to uninstall matplotlib and install the tk and tk-dev packages by using these commands :
sudo apt-get install tk8.5
sudo apt-get install tk-dev
,然后通过pip install matplotlib
重新安装matplotlib但我仍然遇到相同的错误.任何帮助,将不胜感激.我在VirtualBox上使用Ubuntu 14.04,并在virtualenv环境中工作.非常感谢.
and then re-installing matplotlib again by pip install matplotlib
but I am still getting the same error. Any help would be appreciated. I am using Ubuntu 14.04 on VirtualBox and working inside a virtualenv environment.Thanks so much.
推荐答案
我刚刚遇到了这个问题(Ubuntu 15.10,但想法相同),并通过以下方式解决了问题:
I just ran into this (Ubuntu 15.10 but same idea) and fixed it by:
sudo apt-get install tk-dev
pip uninstall -y matplotlib
pip --no-cache-dir install -U matplotlib
我认为第三步很关键;如果允许缓存,则pip
似乎只是在使用先前构建的matplotlib
安装.
I think the third step was the critical one; if the cache is permitted then pip
appeared to be just using the previously-built installation of matplotlib
.
您也可以手动删除以前构建的matplotlib;在Ubuntu上,它位于~/.cache/pip
中的某个位置. (很遗憾,我找不到pip清除其缓存的方法.)
You can also manually remove the previously-built matplotlib; on Ubuntu it lives in ~/.cache/pip
somewhere. (I couldn't find a way for pip to clean up its cache unfortunately.)
这篇关于从matplotlib.backends导入_tkagg ImportError:无法导入名称_tkagg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!