Using Python installed via Anaconda on macOS, figures do not receive keyboard focus. All key presses go to the terminal instead.
Minimal example:
importmatplotlib.pyplotaspltplt.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.
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?
On 2017/11/23 9:19 PM, Clemens Brunner wrote:
Nice, thanks @jklymak <https://github.com/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?
On 2017/11/24 9:55 AM, Clemens Brunner wrote:
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.
Right, no resolution or improvement that I know of. For matplotlib, it
just means it is easiest to use the qt5agg backend instead of the macosx
backend. The qt5agg backend has more features and gets more development
anyway. The Anaconda limitation is annoying, but I wouldn't let it
block a recommendation to use Anaconda on OS X.
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.
[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, 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().
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.
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.
Activity
cbrnr commented on Nov 23, 2017
Update: This only happens when using the (default) osx backend.
dstansby commented on Nov 23, 2017
Are you using the framework build of python? (ie. are you starting python using pythonw)
cbrnr commented on Nov 23, 2017
No. It works with pythonw, but how can I start IPython using this framework build?
jklymak commented on Nov 23, 2017
Here is a magic incantation to get ipython to play w pythonw #8982 (comment)
cbrnr commented on 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 commented on 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 commented on Nov 24, 2017
cbrnr commented on 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 commented on Nov 24, 2017
There is an open issue: ContinuumIO/anaconda-issues#199
jklymak commented on Nov 24, 2017
if you want more bedtime reading ;-)
efiring commented on Nov 24, 2017
cbrnr commented on 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 commented on Nov 24, 2017
#9795 will make it easier to configure the "default" on a user-by-user basis...
tacaswell commented on Nov 25, 2017
I thought qt5 was the default on osx with conda....Did that change recently?
efiring commented on 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 commented on Nov 25, 2017
How did you check this? When I start IPython in Anaconda, I get:
Also, matplotlib.get_backend() returns MacOSX.
efiring commented on 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 commented on 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 commented on Oct 26, 2018
@cbrnr, could you test whether the issue is gone with the fix #12633?
cbrnr commented on 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 commented on Oct 26, 2018
@cbrnr, thanks! Keep us informed if possible.
cbrnr commented on Jun 6, 2019
I tested with the latest Anaconda packages and this issue has been resolved. Thanks!