from matplotlib.backends import _tkagg ImportError: cannot import name _tkagg

后端 未结 5 1697
不思量自难忘°
不思量自难忘° 2021-02-05 10:53

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.         


        
相关标签:
5条回答
  • 2021-02-05 11:22

    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
    
    0 讨论(0)
  • 2021-02-05 11:30

    Python 3.7.4 on Windows 10, replacing NavigationToolbar2TkAgg with NavigationToolbar2Tk works for me.

    Change from:

    from matplotlib.backends.backend_tkagg import ( FigureCanvasTkAgg, NavigationToolbar2TkAgg)

    To:

    from matplotlib.backends.backend_tkagg import ( FigureCanvasTkAgg, NavigationToolbar2Tk)

    0 讨论(0)
  • 2021-02-05 11:38

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

    0 讨论(0)
  • 2021-02-05 11:38

    replacing NavigationToolbar2TkAgg with NavigationToolbar2Tk also works in Python 3.8.5 (MacOS Catalina).

    0 讨论(0)
  • 2021-02-05 11:42

    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.

    0 讨论(0)
提交回复
热议问题