hi! I'm using Pluto for my intro to data science class at Oregon State Uni! :partying_face:
out of 27 students, 4 could not get PyPlot to work with Pluto, getting the following messages.
Julia 1.5.x, Mac usually.
using PyPlot and plotting works fine in REPL, but from within Pluto, I get the following error in my Pluto output:
Distributed.ProcessExitedException(2)
and the following error in my REPL:
From worker 3:
From worker 3: signal (11): Segmentation fault: 11
From worker 3: in expression starting at none:1
From worker 3: _ZNK7QScreen6handleEv at /Users/wisehe/.julia/conda/3/lib/libQt5Gui.5.dylib (unknown line)
From worker 3: Allocations: 18066005 (Pool: 18060522; Big: 5483); GC: 16
Worker 3 terminated.Distributed
.ProcessExitedException(3)
also of note, if I instead use Plots instead of PyPlot then plotting works fine in Pluto.

This is interesting... I am also planning to use Pluto for my lectures and in the moment betting the farm on PyPlot because of missing tricontour etc. in Plots.
I'm one of the students with this issue, here with some more context if it helps. Also, feel free to let me know if you need any additional info.
I am running macOS Mojave, version 10.14.6
I am using Julia version 1.5.2. I have had previous installs of Julia. After I ran into the problem that SimonEnsemble posted I thought I might try to "turn it off and on again."
I deleted my .julia folder. I then opened julia did the following: Added PyPlot and then Pluto from within the REPL package manager mode with ]. In the same session I ran using PyPlotand using Pluto to precompile them. I exited julia. I opened julia again and ran using Pluto and Pluto.run(). I started a new notebook. In the first cell I ran using PyPlot. In the second cell I ran plot([1,2],[1,2]) which is where I got the a very similar error:
From worker 2:
From worker 2: signal (11): Segmentation fault: 11
From worker 2: in expression starting at none:1
From worker 2: _ZNK7QScreen6handleEv at /Users/wisehe/.julia/conda/3/lib/libQt5Gui.5.dylib (unknown line)
From worker 2: Allocations: 19860731 (Pool: 19854373; Big: 6358); GC: 20
Worker 2 terminated.Distributed
.ProcessExitedException(2)
I repeated the above process but didn't close Julia after running using Pluto and then waited until I was in a new Pluto notebook to run using PyPlot and got the same result.
Hi, not sure if this will help as I have no Mac and I am no PyPlot specialist either.
In fact the error message tells me that somehow the code runs through libQt5Gui which IMHO shouldnt happen in the first place, as this corresponds to the matplotlib gui backend which would be started from the REPL. So one idea could be to force a different non-gui backend before starting julia. See the matplolib docs for different options how to do this.
One way you could try would consist in forcing to set the backend via an environment variable:
shell$ MPLBACKEND=Agg julia
julia> using Pluto
julia> Pluto.run()
To cite from PyPlot.jl/src/init.jl:
"PyPlot initialization — the hardest part is finding a working backend".
@j-fu This solved the issue for me! Thank you very much.
Cool so I will know what to tell my students then :)
this didn't work for another student on Mac, who got an error:
/bin/bash: MPLBACKEND=Agg: command not found
when he typed this into the shell from Julia!
we tried export MPLBACKEND=Agg in the terminal of Mac as well.
UPDATE
this means of changing the backend in Pluto before attempting to plot did not work either:
using PyPlot
rcParams = PyPlot.PyDict(PyPlot.matplotlib."rcParams")
rcParams["backend"] = "Agg"
@j-fu
shell$ MPLBACKEND=Agg julia
By "julia" were you referring to the path to julia? In my case I have a symlink to julia in my $PATH. Perhaps that is why it worked for me and not for the other student.
Exactly. This assumes that your PATH contains the directory where the Julia executable is sitting (might be not easy to find on a Mac...) or that you have a symlink into a directory on your path. This then would start the Julia REPL. Unlike python proper, PyPlot does backend initialization during loading, see https://github.com/JuliaPy/PyPlot.jl/blob/e547385265314eb57065309644cf6d8c8a068fa0/src/init.jl#L183 ,
so setting rcparams from within Julia does not work.
An alternative is to put
backend: Agg
into the matplotlib configuration file. On linux it is $HOME/.config/matplotlib/matplotlibrc . Don't know where Apple moved the goalposts regarding this one...
EDIT: another possibility is to put
ENV["MPLBACKEND"]="Agg"
before using PyPlot into the notebook.
I think you also can put
ENV["MPLBACKEND"]="Agg"
into the Pluto/Julia file before using PyPlot.
Finally figured it out!
Let's see if they can fix this soon, otherwise I will temporarily disable the notebook-name-as-process-title feature.
Most helpful comment
Hi, not sure if this will help as I have no Mac and I am no PyPlot specialist either.
In fact the error message tells me that somehow the code runs through libQt5Gui which IMHO shouldnt happen in the first place, as this corresponds to the matplotlib gui backend which would be started from the REPL. So one idea could be to force a different non-gui backend before starting julia. See the matplolib docs for different options how to do this.
One way you could try would consist in forcing to set the backend via an environment variable:
shell$ MPLBACKEND=Agg julia julia> using Pluto julia> Pluto.run()To cite from PyPlot.jl/src/init.jl:
"PyPlot initialization — the hardest part is finding a working backend".