Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Cannot import name _tkagg

📅 2016-Mar-14 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ backend, error, matplotlib, tk ⬩ 📚 Archive


I had Matplotlib installed on a computer. I tried to set the backend for a plot using TkAgg. There was no Tk installed, so I installed the required packages. When I tried to set backend again, I got this error: ImportError: cannot import name _tkagg


Check if your Matplotlib is installed using pip. If so, then you need to reinstall Matplotlib so that it picks up links to the python-tk files correctly:

$ sudo pip uninstall matplotlib
$ sudo pip install matplotlib

The plot was displayed correctly after this.

Tried with: Ubuntu 14.04