PyPlot error and it crashes the REPL

Hi
I installed my Julia ecosystem on a new macbook pro (with mojave 10.14.4 and Julia 1.1.0), and a crash occurs when any PyPlot (version installed: 2.8.1) command is executed. Hereafter an example when I execute the commands in a terminal: PyPlot generates an error and the REPL crashes; I have to kill the terminal. I have the same situation when I execute the instructions under Juno. I tried (1) to reinstall PyPlot (ps: no error is reported), (2) to update the package, and it is not better. Any suggestion to fix it? Also, do you know what to do to prevent this problem for forcoming installs. Thanks.
Xavier

Last login: Tue May 7 11:58:20 on ttys002
MacBook-Pro-de-Xavier:~ xgandibleux$ exec ‘/Applications/Julia-1.1.app/Contents/Resources/julia/bin/julia’
_
_ _ ()_ | Documentation: https://docs.julialang.org
() | () () |
_ _ | | __ _ | Type “?” for help, “]?” for Pkg help.
| | | | | | |/ ` | |
| | |
| | | | (
| | | Version 1.1.0 (2019-01-21)
/ |_‘|||_’_| | Official https://julialang.org/ release
|__/ |

(v1.1) pkg> status
Status ~/.julia/environments/v1.1/Project.toml
[c52e3926] Atom v0.8.5
[2e9cd046] Gurobi v0.6.0
[4076af6c] JuMP v0.19.0
[e5e0dc1b] Juno v0.7.0
[91a5bcdd] Plots v0.24.0
[d330b81b] PyPlot v2.8.1

julia> using PyPlot

julia> x=[2,7,4] ; y=[5,1,8]
3-element Array{Int64,1}:
5
1
8

julia> plot(x,y)
2019-05-07 12:00:16.274 julia[645:19565] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fbef5dfb960
2019-05-07 12:00:16.274 julia[645:19565] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fbef5dfb960’
*** First throw call stack:
(
)
libc++abi.dylib: terminating with uncaught exception of type NSException

signal (6): Abort trap: 6
in expression starting at no file:0
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 14022329 (Pool: 14020162; Big: 2167); GC: 30

[Opération terminée]

The problem is identified. It is a matter of backend invoked on macOS.
The following “workaround” works (see https://github.com/JuliaPy/PyPlot.jl/issues/433):
In the REPL, type ‘using PyPlot’. If the command PyPlot.backend reports tkagg
then the setting is pointing to tk, a backend broken on macOS(?).

  1. add IJulia
  2. and the configuration of the backend in use is updated to qt5;
    the command PyPlot.backend returns qt5agg

It fixes the issues, PyPlot is back!

isn’t it enough to run
ENV["MPLBACKEND"]="qt5agg"
before using PyPlot (and perhaps rebuilding)?

1 Like

Yes, and you only need to do that once. No rebuild required.

I’ve just tagged a new version of PyPlot which tries a bit harder to avoid using tkagg on MacOS — automatically installing pyqt if you are using Conda, or at least printing a warning suggesting that you use MPLBACKEND to specify a different backend.

1 Like