Comments (9)
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.
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.
Perhaps I've searched poorly, but where is examples/embedding/ipkernel_qtapp.py
? Thank you @Carreau
from nbclient.
Dug around a bit more, found it here: ipykernel/examples/embedding/ipkernel_qtapp.py
from nbclient.
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.
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.
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.
Thank you for your help @Carreau
from nbclient.
Holy moly! 🎉 thank you for putting it all together, @GenevieveBuckley!
from nbclient.
Related Issues (20)
- 0.6.1: sphinx faiils because missing file HOT 2
- Background Python process after running tests
- How to reuse exsisting kernel? HOT 4
- Test failure in ipywidgets 8 HOT 2
- nbclient 0.6.6 doesn't report cell magic error properly
- Cell caching HOT 6
- just_run does not close event loop it creates HOT 2
- Project dependencies may have API risk issues HOT 2
- 0.7.1: pytest is failing because missing ` jupyter_core.utils.ensure_async` HOT 11
- jupyter_core version constraint is invalid HOT 3
- nbclient >= 0.7.1 raises ImportError when trying to open a notebook HOT 1
- AttributeError: 'KernelManager' object has no attribute 'cleanup' HOT 5
- `NotebookClient.wait_for_reply` hangs with jupyter_client 8 or later HOT 4
- Is it possible to programmatically inspect variables of a NotebookNode? HOT 5
- output of type `stream` is split over multiple cells HOT 10
- execute_cell running error HOT 4
- ipykernel.comm.Comm is deprecated HOT 3
- Calling `jupyter-execute` runs the notebook but doesn't save it HOT 5
- when cell contains ipywidget , execute cell will sometimes blocks HOT 1
- Executing notebooks with %load and other IPython magic commands HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nbclient.