benjamin-heasly / pyramid

Declarative neuro data synthesis, processing, and trial alignment.
The Unlicense
0 stars 1 forks source link

TkAgg backend is not available on all macOS's. #1

Open benjamin-heasly opened 7 months ago

benjamin-heasly commented 7 months ago

We've been trying to use the matplotlib 'TkAgg' back end on all platforms, since this seems both portable and allows setting/restoring figure positions programmatically.

It seems TkAgg is present on some macOS's, but not all. When it's not present we get an error in gui mode, that TkAgg is not supported on mac. Currently this makes pyramid stop and error out.

Seems like it would be better in this case to continue with a supported back end, event if that means we can't set figure positions.

Some have reported success with the Qt5Agg backend on mac, as in this SO. This seems like an option, if someone is willing and able to install PyQt5, etc. Or, pyramid could just accept the default 'MacOSX' backend on macs.


I'm thinking two ways forward could be:

  1. don't set the matplotlib back end for the user in pyramid code at all, and let users specify this if desired via MPLBACKEND
  2. do set the back end for the user, but somehow detect what's supported (not clear how to do this)
benjamin-heasly commented 7 months ago

As of c47fd17, plotters is not trying set the back end anymore.

I'm leaving this open through because I think there's more to think about.

benjamin-heasly commented 2 weeks ago

There's more to sort through with the macos backend.

Several tests in test_plotters.py use Pyramid figure controller update() and/or matplotlib canvas flush_events(). These sometimes just hang and stall the test run forever. It seems to happen the second time one of these is called during a test. Maybe a system event loop is not getting "pumped" during the test, causing an indefinite wait.

I've seen this happen when running the tests through hatch (hatch run test:cov), though, curiously, not when running via the VS Code pytest UI. Oddly, when I printed the matplotlib.get_backend() in each case, I got a slightly different result: MacOSX via the VS Code pytest UI, vs lowercase macosx vi hatch. Are those backends different?

I saw this on macOS Sonoma 14.5 with matplotlib version 3.8.0.

Maybe we need to be more defensive when touching the backend from tests.

benjamin-heasly commented 2 weeks ago

The docs here say "The names of builtin backends are case-insensitive; e.g., 'QtAgg' and 'qtagg' are equivalent." But it still is odd to see different results, suggesting different code paths used from each test runner.

benjamin-heasly commented 2 weeks ago

Does the difference have to do with a "framework" vs "non-framework" Python build? This is out of date but maybe still relevant in some way?

https://matplotlib.org/2.0.2/faq/osx_framework.html