# PyPlot error and it crashes the REPL

**URL:** <https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957>\
**Category:** General Usage\
**Tags:** pyplot\
**Created:** [May 7, 2019, 10:40am UTC](https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957 "2019-05-07T10:40:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![XavierG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavierg/32/1768_2.png) [@XavierG](https://discourse.julialang.org/u/XavierG)\
**Post date:** [May 7, 2019, 10:40am UTC](https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957/1 "2019-05-07T10:40:52Z")

</div>

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](https://docs.julialang.org)  
(_) | (_) (_) |  
\_ \_ | | \_\_ \_ | Type “?” for help, “]?” for Pkg help.  
| | | | | | |/ ` | |  
| | || | | | (_| | | Version 1.1.0 (2019-01-21)  
_/ |\ __‘_|_|_|\__ ’\_| | Official [https://julialang.org/](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]

---

<div class="post-metadata">

**Author:** ![XavierG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xavierg/32/1768_2.png) [@XavierG](https://discourse.julialang.org/u/XavierG)\
**Post date:** [May 7, 2019, 1:36pm UTC](https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957/2 "2019-05-07T13:36:02Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [May 7, 2019, 2:36pm UTC](https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957/3 "2019-05-07T14:36:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 4, 2019, 1:06am UTC](https://discourse.julialang.org/t/pyplot-error-and-it-crashes-the-repl/23957/4 "2019-09-04T01:06:37Z")

</div>

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.
