gscreen breaks with import matplot

More
03 Aug 2022 13:40 #248932 by thadwald
Hi

I am trying to use metplotlib for displaying a simple automated/guided CAM solution in gscreen (linuxcnc 2.8.2)

Following metplotlib tutorial, for using metplot with gtk2, I try the following line:
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas

gscreen fails with the following error:
2
Traceback (most recent call last):
  File "/usr/bin/gscreen", line 4661, in <module>
    app = Gscreen()
  File "/usr/bin/gscreen", line 792, in __init__
    self.initialize_widgets()
  File "/usr/bin/gscreen", line 1086, in initialize_widgets
    self.init_dro_colors()
  File "/usr/bin/gscreen", line 1196, in init_dro_colors
    self.widgets.abs_colorbutton.set_color(gtk.gdk.color_parse(self.data.abs_textcolor))
  File "/usr/bin/gscreen", line 228, in __getattr__
    if r is None: raise AttributeError, "No widget %r" % attr
AttributeError: No widget 'abs_colorbutton'

I suspect that maybe the import statement references gtk3 libraries but this is just a guess.
Any suggestions?

Please Log in or Create an account to join the conversation.

More
03 Aug 2022 14:06 #248933 by thadwald
I have also tried
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas

I get the same results

Please Log in or Create an account to join the conversation.

More
03 Aug 2022 22:40 #248981 by andypugh
This looks like a funny one, maybe a namespace clash, for example.

Just as a check, if you comment-out the import matplot.... Does it all work again?

Please Log in or Create an account to join the conversation.

More
04 Aug 2022 00:06 #248990 by thadwald
Yes. It works fine with the other matplot import. It appears to be the gtk one that causes the problem.

Please Log in or Create an account to join the conversation.

More
04 Aug 2022 01:17 - 04 Aug 2022 01:20 #248992 by cmorley
have you tried your import just in a python session?
Gscreen some times hides the real error.
Did you check the terminal or is that error from the dialog box?
The terminal usually shows more.

But I would confirm the library imports all by it's self first.
You can also wrap a try statement around it:
try:
    from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
except Exception as detail:
    print (detail)

then look in the terminal.
Last edit: 04 Aug 2022 01:20 by cmorley.
The following user(s) said Thank You: thadwald

Please Log in or Create an account to join the conversation.

More
04 Aug 2022 01:39 #248994 by thadwald
Thank you. There is actually an issue with the import statement and, like you said, gscreen was hiding it.

I have been running from terminal precisely to see these errors but this one didn't show up until explicitly trapped. 

Thanks again!
The following user(s) said Thank You: cmorley

Please Log in or Create an account to join the conversation.

More
04 Aug 2022 13:16 - 04 Aug 2022 13:19 #249035 by thadwald
Follow-up
The root cause was that pip installs matplotlib by default without GTK C extensions.

using:
pip install matplotlib --no-binary=matplotlib

forces it to build the binaries, which then include the required GTK parts.
Last edit: 04 Aug 2022 13:19 by thadwald.

Please Log in or Create an account to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum