Skip to content

Fix macosx verify later #12557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 18, 2018

PR Summary

This moves the verification of the framework build out of import _macosx, allowing us to
call that more often, and into the creation of the figure manager...

Closes #12188

Update (19 Oct 2018)

Moved MacOSx framework check to pyplot.py so it errors at the same place as before rather than waiting for a draw.

Note this doesn't fix the bouncing icon in the framework build if one indeed wants to use the macosx backend, but it doesn't pop one up everytime regardless of the backend.

Not sure what changed in 3.0 to cause the icon to start bouncing, but this should cure the problem for 75% of the users who just want to use Matplotlib with a different backend, like a notebook...

Icon bouncing is because we initialize the window manager connection to python, but we don't open a window, so the app is in an in-between state of readiness.

Until conda ships a python that we can test if its a FRAMEWORK app, I am not sure we will fix this any better than this. Note the vast improvement here is that the bouncing doesn't happen for every backend like it does in 3.0.0

Non-framework python

this PR

>>> import matplotlib; matplotlib.use('macosx'); import matplotlib.pyplot

yields: No icon popped up and

Traceback (most recent call last):
  File "testbackend.py", line 3, in <module>
    import matplotlib.pyplot
  File "/Users/jklymak/matplotlib/lib/matplotlib/pyplot.py", line 2357, in <module>
    "Python is not installed as a framework. The Mac OS X backend "
ImportError: Python is not installed as a framework. The Mac OS X backend will not be able to function 
correctly if Python is not  installed as a framework. See the Python documentation for more  
information on installing Python as a framework on Mac OS X. Please either reinstall Python as a 
framework, or try one of the other backends. If you are using (Ana)Conda please install python.app 
and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib 
FAQ for more information.

V 2.2.3

As above, though the stacktrace is deeper:

 File "<stdin>", line 1, in <module>
  File "/Users/jklymak/matplotlib/lib/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/jklymak/matplotlib/lib/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/Users/jklymak/matplotlib/lib/matplotlib/backends/backend_macosx.py", line 17, in <module>

V3.0.0

Error is on import as above.

Framework python

V3.0.0

>>>  import matplotlib; matplotlib.use('macosx'); import matplotlib.pyplot as pyplot

Icon pops up, bounces, and terminal loses focus.

>>>  import matplotlib; matplotlib.use('qt5agg'); import matplotlib.pyplot as pyplot

Icon pops up, bounces, and terminal loses focus.

this PR

>>>  import matplotlib; matplotlib.use('macosx'); import matplotlib.pyplot as pyplot

Icon bounces until a draw is called and terminal loses focus but focus returns to terminal.

>>>  import matplotlib; matplotlib.use('qt5agg'); import matplotlib.pyplot as pyplot

No icon pops up....

V2.2.3

>>>  import matplotlib; matplotlib.use('macosx'); import matplotlib.pyplot as pyplot

Icon pops up, but doesn't bounce.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@jklymak jklymak added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Oct 18, 2018
@jklymak jklymak added this to the v3.0.x milestone Oct 18, 2018
@jklymak
Copy link
Member Author

jklymak commented Oct 18, 2018

Note that moving the check later is kind of an API change.

@jklymak jklymak requested a review from anntzer October 18, 2018 19:45
@jklymak
Copy link
Member Author

jklymak commented Oct 18, 2018

So, previously, the check triggered on import matplotlib.pyplot as plt now it doesn't trigger until plt.plot()

import matplotlib; matplotlib.use('macosx'); import matplotlib.pyplot as plt; plt.plot(range(10))

@anntzer
Copy link
Contributor

anntzer commented Oct 18, 2018

AFAICT this "won't work" for reasons explained in #12188 (comment). Not that I have a better solution though.

@anntzer anntzer removed their request for review October 18, 2018 20:40
@jklymak
Copy link
Member Author

jklymak commented Oct 18, 2018

Thanks for the detailed comment in
#12188 (comment)

I'll still argue that the proposed change here is "better", even if it doesn't give mac users the fallback as desired.

Right now if we use the non-framework build on a Mac, and no backend is specified, and we don't call matplotlib.use, macosx will try to run with the macosx backend, and will fail when the figure manager is instantiated because verify_framework will return False. Then the user then knows that they should change to the framework build, or manually set their backend.

Yes, it'd be slicker to fallback to Qt5 etc, but I think this proposed behaviour is better than popping up the _macosx GUI every time we import pyplot, even if the user is using a Jupyter Notebook, or has manually set in the matplotlibrc to Qt5Agg, etc.

[Slightly tangential: I'd still actually argue we shouldn't outright fail using the non-framework Mac build. Yes some interactivity is broken, but you can still make plots. I'd change the Error to a Warning.]

@anntzer
Copy link
Contributor

anntzer commented Oct 18, 2018

The argument seems reasonable, and I honestly can't pretend I care enough about OSX subtleties to have a strong opinion against (or for) the changes here, as long as you understand the pros and cons I explained.

@jklymak
Copy link
Member Author

jklymak commented Oct 18, 2018

... well I don't care about the subtleties of OSX pythons either, but I guess we can't break Matplotlib for our Mac users given that a pretty big fraction of the scientific community uses Macs. This isn't just conda - it affects the system Framework build and the macports build as well.

@anntzer
Copy link
Contributor

anntzer commented Oct 18, 2018

I'm not saying that the fix is not important, just that I can't really judge the tradeoffs involved in either approach.

@tacaswell
Copy link
Member

@jklymak this needs a rebase....

@jklymak
Copy link
Member Author

jklymak commented Oct 24, 2018

Obsoleted by #12603

@jklymak jklymak closed this Oct 24, 2018
@QuLogic QuLogic modified the milestones: v3.0.x, unassigned Oct 24, 2018
@jklymak jklymak deleted the fix-macosx-verify-later branch October 24, 2018 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: MacOSX OS: Apple Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matplotlib 3 pyplot on MacOS bounces rocket icon in dock
4 participants