Skip to content

No keyboard focus in figures on macOS with Anaconda #9839

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
cbrnr opened this issue Nov 23, 2017 · 22 comments
Closed

No keyboard focus in figures on macOS with Anaconda #9839

cbrnr opened this issue Nov 23, 2017 · 22 comments

Comments

@cbrnr
Copy link
Contributor

cbrnr commented Nov 23, 2017

Using Python installed via Anaconda on macOS, figures do not receive keyboard focus. All key presses go to the terminal instead.

Minimal example:

import matplotlib.pyplot as plt
plt.plot(1)
plt.show()
# then click on the "Save" icon
# it is impossible to change the file name in the dialog window

The same thing happens when listening to key press events - they are simply not detected at all.

Using Python installed via Homebrew doesn't have this problem. There are some reports regarding this behavior (#665, #2120, #3367, #4372), but I still run into this issue. I'm using the latest Anaconda packages and tried the latest Matplotlib release and latest development version.

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 23, 2017

Update: This only happens when using the (default) osx backend.

@dstansby
Copy link
Member

Are you using the framework build of python? (ie. are you starting python using pythonw)

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 23, 2017

No. It works with pythonw, but how can I start IPython using this framework build?

@jklymak
Copy link
Member

jklymak commented Nov 23, 2017

Here is a magic incantation to get ipython to play w pythonw #8982 (comment)

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 24, 2017

Nice, thanks @jklymak this works! I wish Anaconda made pythonw the default for everything to avoid these kinds of tricks. Has anyone ever asked them why they don't want to play nice with macOS frameworks?

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

Ha ha. I think there are a few threads about it.... I don't understand the issue, but, I don't use ipython except via jupyter notebooks, so...

@efiring
Copy link
Member

efiring commented Nov 24, 2017 via email

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 24, 2017

OMG what's the tl;dr? I assume not much has happened. This is the one reason why I can't recommend Anaconda on macOS without any reservations.

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

There is an open issue: ContinuumIO/anaconda-issues#199

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

if you want more bedtime reading ;-)

@efiring
Copy link
Member

efiring commented Nov 24, 2017 via email

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 24, 2017

You're right, but the problem with this is that osx is the default backend. If it wasn't this wouldn't be such a big issue. Anaconda could probably change the default to qt5 because PyQt5 gets installed anyway.

@jklymak
Copy link
Member

jklymak commented Nov 24, 2017

#9795 will make it easier to configure the "default" on a user-by-user basis...

@tacaswell
Copy link
Member

I thought qt5 was the default on osx with conda....Did that change recently?

@efiring
Copy link
Member

efiring commented Nov 25, 2017

[I just checked by installing from defaults (version 2.0.2) and from conda-forge (version 2.1.0), and in both cases the backend default is qt5agg.] This is with Python 3.6.
Correction: The original comment above (now in brackets) is incorrect. Both versions provide matplotlibrc files in which the backend is macosx. The conda recipes are not modifying the default that we supply.

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 25, 2017

How did you check this? When I start IPython in Anaconda, I get:

In [1]: %matplotlib
Using matplotlib backend: MacOSX

Also, matplotlib.get_backend() returns MacOSX.

@efiring
Copy link
Member

efiring commented Nov 25, 2017

@cbrnr, thanks for keeping after this--I wasn't being careful enough. It turns out I didn't check something that I thought I had checked, and the upshot is that my backend was being set from my own matplotlibrc file, not from the one installed by conda.

Side note: it's far from obvious, but to find out which matplotlibrc file is being used one can call matplotlib.matplotlib_fname().

@cbrnr
Copy link
Contributor Author

cbrnr commented Nov 29, 2017

So what's the plan? The best solution would be if Anaconda defaulted their Python executables to a framework build (something everyone else is doing, seems to have no negative side effects and makes Python run smoothly on macOS). Alternatively, as a workaround, they could change the default matplotlib backend to qt5 (on Macs) - not sure if this is feasible though because this would mean introducing PyQt5 as a hard dependency of matplotlib.

@Mottl
Copy link
Contributor

Mottl commented Oct 26, 2018

@cbrnr, could you test whether the issue is gone with the fix #12633?

import matplotlib
matplotlib.use('macosx')
import matplotlib.pyplot as plt
plt.plot(1)
plt.show()

@cbrnr
Copy link
Contributor Author

cbrnr commented Oct 26, 2018

I tried, but cloning stalls after an hour or so, so I can't test with this PR. However, I noticed that my example from my initial post does work in Anaconda now. Unless I create a new env, I then get a segfault. So I'm not sure what's wrong with Anaconda on my machine, I never seem to get it to work properly.

@Mottl
Copy link
Contributor

Mottl commented Oct 26, 2018

@cbrnr, thanks! Keep us informed if possible.

@cbrnr
Copy link
Contributor Author

cbrnr commented Jun 6, 2019

I tested with the latest Anaconda packages and this issue has been resolved. Thanks!

@cbrnr cbrnr closed this as completed Jun 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants