Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#60175 closed defect (worksforme)

cannot import name '_tkagg' from 'matplotlib.backends' in python 2.7 and python 3.8

Reported by: lpagani91 Owned by: reneeotten (Renee Otten)
Priority: Normal Milestone:
Component: ports Version: 2.6.2
Keywords: Cc:
Port: py-matplotlib

Description (last modified by mf2k (Frank Schima))

I have problems importing tkagg in a python program, though it used to work (I ran the same python program in the past):

In [9]: matplotlib.__version__                                                  
Out[9]: '3.1.3'
In [10]: from matplotlib.backends.backend_tkagg import FigureCanvasTkagg        
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-10-b2c6c8b92aa8> in <module>
----> 1 from matplotlib.backends.backend_tkagg import FigureCanvasTkagg

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/backends/backend_tkagg.py in <module>
----> 1 from . import _backend_tk
      2 from .backend_agg import FigureCanvasAgg
      3 from ._backend_tk import (
      4     _BackendTk, FigureCanvasTk, FigureManagerTk, NavigationToolbar2Tk)
      5 

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/backends/_backend_tk.py in <module>
     20 from matplotlib.figure import Figure
     21 from matplotlib.widgets import SubplotTool
---> 22 from . import _tkagg
     23 
     24 try:

ImportError: cannot import name '_tkagg' from 'matplotlib.backends' (/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/matplotlib/backends/__init__.py)

I searched the web but all similar problems were linked to Windows or Ubuntu. Tkinter was not installed in my latest Python versions so I added it and some people mention that I should uninstall matplotlib and reinstall it after having installed Tkinter but it did not help.

Change History (7)

comment:1 Changed 4 years ago by mf2k (Frank Schima)

In the future, please use WikiFormatting and add the port maintainer(s) to Cc (port info --maintainers py38-matplotlib), if any.

comment:2 Changed 4 years ago by mf2k (Frank Schima)

Keywords: python libraries removed
Owner: set to reneeotten
Port: py-matplotlib added; pyxx-matplotlib removed
Status: newassigned

comment:3 Changed 4 years ago by mf2k (Frank Schima)

Description: modified (diff)

comment:4 Changed 4 years ago by reneeotten (Renee Otten)

what is the output of port installed | grep matplotlib? I suspect that you didn't install the +tkinter variant, in that case the TkAgg backend will not be available. Additionally, it appears there is a typo in your import statement; I'm pretty sure it should be FigureCanvasTkAgg (note the capital "A" in "Agg").

So can you please do sudo port install pyXY-matplotlib +tkinter, correct your import statement and try again? Let us know if that resolved your problem!

comment:5 Changed 4 years ago by lpagani91

OK, I thought installing pyXY-tkinter was the thing to do. How could I know that I have to install matplotlib +tkinter instead ?? The Agg typo is only in trials by hand. The code was correctly spelled Agg After installing with the +tkinter option, it works. Thanks, folks!

comment:6 Changed 4 years ago by reneeotten (Renee Otten)

Resolution: worksforme
Status: assignedclosed

comment:7 in reply to:  5 Changed 4 years ago by reneeotten (Renee Otten)

Replying to lpagani91:

OK, I thought installing pyXY-tkinter was the thing to do. How could I know that I have to install matplotlib +tkinter instead ??

Installing pyXY-tkinter is indeed one of the things that need to happen, besides setting the activating the backend tkagg=True in setup.cfg. You can do port variant pyXY-matplotlib, which will give you a (short) description of all variants and their purpose. In this case that said "tkinter: Enable TkAgg backend", that would likely have given you sufficient information about which variant to install.

Note: See TracTickets for help on using tickets.