JuliaPy / PyPlot.jl

Plotting for Julia based on matplotlib.pyplot
https://github.com/JuliaPy/PyPlot.jl
MIT License
475 stars 87 forks source link

PyPlot Crashing Mac OS 10.14.6 #454

Closed ghost closed 5 years ago

ghost commented 5 years ago

I am using Mac OS 10.14.6 and Julia 1.1.1.

I just executed a script in the Julia terminal, imported PyPlot, and got logged out of my computer upon executing plot. After logging back in, I was able to recover my Julia session which said:

2019-08-09 14:30:47.868 julia[5602:179629] HIToolbox: received notification of WindowServer event port death.
2019-08-09 14:30:47.868 julia[5602:179629] port matched the WindowServer port created in BindCGSToRunLoop

I'll restart my computer to see if this persists, but something in the pipeline seems to have gone adrift!

ghost commented 5 years ago

Even after restarting my computer I get the similar error message:

2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:49:53.190 julia[560:8205] CGSTrackingRegionSetIsEnabled returned CG error 268435459
2019-08-09 14:50:03.214 julia[560:8205] HIToolbox: received notification of WindowServer event port death.
2019-08-09 14:50:03.214 julia[560:8205] port matched the WindowServer port created in BindCGSToRunLoop
1-element Array{PyCall.PyObject,1}: PyObject <matplotlib.lines.Line2D object at 0x130d8be10>

ghost commented 5 years ago

Even after restarting and removing and adding PyPlot, the problem persists.

thuwzr commented 5 years ago

The same problem for me.

sunqingmeteo commented 5 years ago

Similar error for me. When I use matplotlib excute "plt.show()". Mac went back to lock screen and need password. Seem like restart system.

Error Info: python[70866:7884671] HIToolbox: received notification of WindowServer event port death.

sunqingmeteo commented 5 years ago

I think the problem was caused by conda to set python environment and did not have figure show windows like X11.

dgleich commented 5 years ago

Seems this happened with the recent update. https://discussions.apple.com/thread/250550587?answerId=251098439022#251098439022

Also, I ran using Conda; Conda.update()

to update all the PyPlot Conda stuff it installs behind the hood. This stopped the crashing, but it doesn't exactly work with the GUI... (but I think the PlotPane works in Atom...)

I don't get figure windows after doing

stevengj commented 5 years ago

What is PyPlot.backend?

dgleich commented 5 years ago
julia> PyPlot.backend
"TkAgg"
stevengj commented 5 years ago

The TkAgg backend has been broken on MacOS for a while (#410), due to an upstream bug in the Python tkinter library. (It crashes if you use it from Python as well.)

However, the current version of PyPlot does not use tkagg by default anymore on MacOS for this reason. The only way it could be using tkagg is if you "forced" it to by specifying it in either your .matplotlibrc file or via the MPLBACKEND environment variable.

You can find the location of your matplotlibrc file by doing:

using PyCall
pyimport("matplotlib").matplotlib_fname()

See if it has a line like backend: TkAgg

dgleich commented 5 years ago

Hmm... nothing with backend seems to be listed Curious!

julia> pyimport("matplotlib").matplotlib_fname()
"/Users/dgleich/.julia/conda/3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc"
shell> grep backend /Users/dgleich/.julia/conda/3/lib/python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
## The default backend. If you omit this parameter, the first
## working backend from the following list is used:
## You can also deploy your own backend outside of matplotlib by
## 'module://my_backend'.
#backend      : Agg
## The port to use for the web server in the WebAgg backend.
## if you are running pyplot inside a GUI and your backend choice
## you if backend_fallback is True
#backend_fallback: True
                         ## This only affects the Agg backend.
                                ## backends but will workd with temporary file based ones:
### tk backend params
### ps backend params
### pdf backend params
### svg backend params
#animation.writer : ffmpeg         ## MovieWriter 'backend' to use
stevengj commented 5 years ago

The other reason it would try tkagg is if all of the other backends fail.

Does

using PyCall
pyimport_conda("PyQt5", "pyqt")

work?

dgleich commented 5 years ago

Great! That installed nicely and that does work!

Results:

julia> pyimport_conda("PyQt5", "pyqt")
[ Info: Installing PyQt5 via the Conda pyqt package...
[ Info: Running `conda install -y pyqt` in root environment
Collecting package metadata (current_repodata.json): done
Solving environment: done

restart julia (probably not necessary, but I was being careful...)

julia> using PyPlot

julia> PyPlot.backend
"Qt5Agg"
stevengj commented 5 years ago

@dgleich, that's great, but I'm still confused — the function pyimport_conda("PyQt5", "pyqt") should be called automatically when PyPlot is initialized since the qt5 backend is the default first choice it tries on macos.

dgleich commented 5 years ago

I had a feeling you'd be as confused as I was about that .. I spent a few minutes trying to debug at the computer having the problem last night, but didn't quite get there. I'll take another look tonight and see what I can dig out.

My quick guess is that default is coming back 'none' ?

stevengj commented 5 years ago

Oh, right, it only installs qt5 automatically if that GUI was explicitly requested, not if it goes through the search list.

I should change that, maybe at least add an optional prompt to install it.

stevengj commented 5 years ago

Okay, I've pushed a patch which forces it to install pyqt on MacOS if nothing else was installed and you are using Conda, and it at least prints a warning if you try to make it use TkAgg on MacOS.

dgleich commented 5 years ago

Fantastic! I think that's the right call. Also, got to check that computer right now...

In this case, the default backend that comes from Matplotlib is:

julia> matplotlib = pyimport_conda("matplotlib","matplotlib")
julia> rcParams = PyDict(matplotlib."rcParams")
julia> default = lowercase(get(ENV, "MPLBACKEND",
                            getnone(rcParams, "backend", "none")))
julia> default
"macosx"