GithubHelp home page GithubHelp logo

Comments (9)

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024 1

Does it help to add a sleep cell?

Yes! That works now!!! 🎉

Let's move this conversation back over to napari/napari#1568 while we discuss things that are not nbclient (I don't want to spam people watching this repository unnecessarily)

from nbclient.

Carreau avatar Carreau commented on July 26, 2024

I'm not too sure, I think app is made to work with examples/embedding/ipkernel_qtapp.py, and otherwise we likely don't want to call any sys-exit()-ish as – as you showed this can in-process.

from nbclient.

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024

Perhaps I've searched poorly, but where is examples/embedding/ipkernel_qtapp.py? Thank you @Carreau

from nbclient.

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024

Dug around a bit more, found it here: ipykernel/examples/embedding/ipkernel_qtapp.py

from nbclient.

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024

Interesting, I can run @jni's example notebook with runipy. That project is no longer maintained now that jupyter_client has an execute method, but perhaps the differences between the two projects will give us a clue.

Sadly I wasn't able to run this similar notebook with the %gui qt magic, that's closer to what we actually want to do.

# cell 1
%gui qt

# cell 2
import napari
viewer = napari.Viewer()
runipy error details - Click to expand!
10/26/2020 06:22:54 PM INFO: Running cell:
%gui qt

10/26/2020 06:22:54 PM INFO: Cell returned
10/26/2020 06:22:54 PM INFO: Running cell:
import napari

viewer = napari.Viewer()

10/26/2020 06:22:57 PM INFO: Cell raised uncaught exception:
�[1;31m---------------------------------------------------------------------------�[0m
�[1;31mRuntimeError�[0m                              Traceback (most recent call last)
�[1;32m<ipython-input-2-63db54b875ee>�[0m in �[0;36m<module>�[1;34m�[0m
�[0;32m      1�[0m �[1;32mimport�[0m �[0mnapari�[0m�[1;33m�[0m�[1;33m�[0m�[0m
�[0;32m      2�[0m �[1;33m�[0m�[0m
�[1;32m----> 3�[1;33m �[0mviewer�[0m �[1;33m=�[0m �[0mnapari�[0m�[1;33m.�[0m�[0mViewer�[0m�[1;33m(�[0m�[1;33m)�[0m�[1;33m�[0m�[1;33m�[0m�[0m
�[0m
�[1;32mc:\users\genevieve\anaconda3\envs\napari\lib\site-packages\napari\viewer.py�[0m in �[0;36m__init__�[1;34m(self, title, ndisplay, order, axis_labels, show)�[0m
�[0;32m     64�[0m                 �[1;34m" Then, restart IPython."�[0m�[1;33m�[0m�[1;33m�[0m�[0m
�[0;32m     65�[0m             )
�[1;32m---> 66�[1;33m             �[1;32mraise�[0m �[0mRuntimeError�[0m�[1;33m(�[0m�[0mmessage�[0m�[1;33m)�[0m�[1;33m�[0m�[1;33m�[0m�[0m
�[0m�[0;32m     67�[0m �[1;33m�[0m�[0m
�[0;32m     68�[0m         �[1;32mif�[0m �[0mperf_config�[0m�[1;33m:�[0m�[1;33m�[0m�[1;33m�[0m�[0m

�[1;31mRuntimeError�[0m: napari requires a Qt event loop to run. To create one, try one of the following:
  - use the `napari.gui_qt()` context manager. See https://github.com/napari/napari/tree/master/examples for usage examples.
  - In IPython or a local Jupyter instance, use the `%gui qt` magic command.
  - Launch IPython with the option `--gui=qt`.
  - (recommended) in your IPython configuration file, add or uncomment the line `c.TerminalIPythonApp.gui = 'qt'`. Then, restart IPython.
10/26/2020 06:22:57 PM INFO: Shutdown kernel
10/26/2020 06:22:57 PM WARNING: Exiting with nonzero exit status

from nbclient.

jni avatar jni commented on July 26, 2024

thanks @GenevieveBuckley for investigating!

Sadly I wasn't able to run this similar notebook with the %gui qt magic

Does it help to add a sleep cell?

# cell 1
%gui qt

# cell 2
import time
time.sleep(5)

# cell 3
import napari
viewer = napari.Viewer()

?

from nbclient.

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024

This issue can be closed, we've worked out what our problem was.

For anyone else running in to the same thing: the problem with nbclient is that we need a separate time.sleep(1) cell, that comes after the cell with the %gui qt magic, and before the cell where we import the library that needs to use Qt. The magic is an asynchronous process, and for reasons that remain mysterious to me you can't put the sleep in the same cell as the magic (which is what I tried earlier).

To modify @jni's example notebook from the gist slightly, this now works:

# cell 1
%gui qt
%matplotlib qt

# cell 2
import time
time.sleep(2)

# cell 3
import matplotlib.pyplot as plt
import numpy as np

plt.scatter(*np.random.random((2, 10)))

from nbclient.

GenevieveBuckley avatar GenevieveBuckley commented on July 26, 2024

Thank you for your help @Carreau

from nbclient.

jni avatar jni commented on July 26, 2024

Holy moly! 🎉 thank you for putting it all together, @GenevieveBuckley!

from nbclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.