from matplotlib.backends import _tkagg ImportError

2019-03-24 19:29发布

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

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

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.

3条回答
相关推荐>>
2楼-- · 2019-03-24 20:04

One answer to this question suggests the error is due to a missing Visual C++ Redistributable for Visual Studio 2015 . Installing it solved the problem for me.

查看更多
Emotional °昔
3楼-- · 2019-03-24 20:16

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

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.

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.)

查看更多
Explosion°爆炸
4楼-- · 2019-03-24 20:18

Try following this scenario:

sudo apt-get update

sudo apt-get install tk tk-dev

sudo pip uninstall matplotlib 

sudo pip install matplotlib

EDIT:

Try:

sudo pip uninstall matplotlib 

sudo apt-get install python-matplotlib

EDIT2:

sudo apt-get install tk8.6-dev

sudo apt-get remove python-matplotlib

sudo apt-get install python-matplotlib
查看更多
登录 后发表回答