jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.71k stars 4.95k forks source link

`%matplotlib qt5` freezes notebook execution #2025

Open godaygo opened 7 years ago

godaygo commented 7 years ago

After updating to Python 3.6 and PyQt 5.7.1, when I use magic %matplotlib qt5 and Restart & Run All button the execution freezes after cell with %matplotlib qt5. (When I evaluate notebook cell by cell it works OK as expected)

qt

The problem relates only to qt5 backend (PyQt 5.7.1).

When I set up c.InteractiveShellApp.matplotlib = 'qt5' in IPython config file, %matplotlib qt5 works OK. When I commented it again execution freezes. Code to play with:

In[1]:  %matplotlib qt5
        import matplotlib.pyplot as plt

In[2]:  fig, ax = plt.subplots(figsize=(12, 8), facecolor='w')
        ax.plot([1,2,3])
        plt.show()

Also for all related buttons Run All, Run All Below the behavior is the same after kernel restart.

Python 3.6 IPython 5.1.0 ipykernel 4.5.2 notebook 4.3.1 PyQt5 5.7.1 Windows 10

gnestor commented 7 years ago

Ping @Carreau

Carreau commented 7 years ago

Yeah, I think we have seen this one before. The problem is we have no clue why. I'm going to guess a ZMQ/Qt event loop integration.

It's really complex to debug, and none of us a Qt5 experts. I'll add that on my loong todo list.

kronos29296 commented 7 years ago

I have a similar problem where if I use %pylab with qt5 freezes when I restart and run all. The plot is displayed when I do a reconnect. Any form of run all with qt5 freezes. I have tried it with %matplotlib and the same problem persists.

When I reconnect though the plot is displayed, the cells are not numbered and still have *. There are no problems when I use something else like tk though.

IVN-tone commented 4 years ago

Does anybody know the solution of this problem? I have the same issue. When I try to execute simple plot:

import pyqtgraph as pg import numpy as np x = np.random.normal(size=1000) y = np.random.normal(size=1000) pg.plot(x, y, pen=None, symbol='o') ## setting pen=None disables line drawing

but when I try work even with simple window:

import sys from PyQt5 import QtGui def window(): app = QtGui.QApplication(sys.argv) w = QtGui.QWidget() b= QtGui.QLabel(w) b.setText("Hello World!") w.setGeometry(100,100,200,50) b.move(50,20) w.setWindowTitle('PyQt') w.show() sys.exit(app.exec_()) if __name__ == '__main__': window()

it freezes the notebook irreversibly.

ChristofKaufmann commented 2 years ago

This is also an issue in VS Code. See also the same issue described here: https://github.com/ipython/ipython/issues/5629

EricThomson commented 1 year ago

Just wanted to chime in with -- I have been experiencing this in Windows for years. When I use %matplotlib qt, and try to run another code cell, that cell hangs (with asterisk). Until I click the 'Interrupt the kernel' button, or run another code cell. Then the first cell runs. The second one hangs until I repeat that process.

Markdown cells run fine, and I can edit/delete other cells. It is only the Python interpreter that seems to be locked when in qt mode. You can imagine presentations/demos are fun :sweat_smile:

I'm not sure if this is a Matplotlib or Jupyter or zmq or Qt thing (all of the above?), but it would be amazing if we could figure this out (maybe let's get together at Scipy and figure it out -- it's that easy right? :smile:). Note I haven't actually tested this thoroughly in non-Windows OS. I easily could.

Edit: I'm on Windows 10 and using notebook 6.5.4 and waiting on this to be fixed: https://github.com/bokeh/jupyter_bokeh/issues/195

So maybe with notebook 7 this will no longer be an issue? Will report back once all that is figured out.