Skip to content

Commit c1943a9

Browse files
committed
try harder to avoid buggy tkagg backend on MacOS, and warn if the user specifies it explicitly (closes #454)
1 parent d9553d3 commit c1943a9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/init.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ function find_backend(matplotlib::PyObject)
112112
if PyCall.gui == :default
113113
# try to ensure that GUI both exists and has a matplotlib backend
114114
for (g,b) in options
115+
if Sys.isapple() && g == :tk && default != "tkagg" && conda
116+
# tkagg backend crashes badly on MacOS
117+
g, b = try
118+
@info "Installing pyqt package to avoid buggy tkagg backend."
119+
pyimport_conda("PyQt5", "pyqt")
120+
:qt5, gui2matplotlib[:qt5]
121+
catch
122+
:none, "agg"
123+
end
124+
end
115125
if g == :none # Matplotlib is configured to be non-interactive
116126
pygui(:default)
117127
matplotlib."use"(b)
@@ -178,6 +188,9 @@ function __init__()
178188
# workaround JuliaLang/julia#8925
179189
global backend = backend_gui[1]
180190
global gui = backend_gui[2]
191+
if Sys.isapple() && gui == :tk
192+
@warn "PyPlot is using tkagg backend, which is known to cause crashes on MacOS (#410); use the MPLBACKEND environment variable to request a different backend."
193+
end
181194

182195
copy!(plt, pyimport("matplotlib.pyplot")) # raw Python module
183196

0 commit comments

Comments
 (0)