ipython / ipython/ipykernel

Error starting an ipykernel without ipywidgets installed

Aperta
#451 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
734
Fork
412
Merge medio
1g 5h
PR unite (30g)
8

Descrizione

Because of the hardcoded hack in ipykernel, I'm getting an error when trying to start a python kernel without widgets installed:

```raw
Traceback (most recent call last):
File "[snip]/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "[snip]/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "[snip]/lib/python3.6/site-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "[snip]/lib/python3.6/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "", line 2, in initialize
File "[snip]/lib/python3.6/site-packages/traitlets/config/application.py", line 87, in catch_config_error
return method(app, *args, **kwargs)
File "[snip]/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 463, in initialize
self.init_extensions()
File "[snip]/lib/python3.6/site-packages/ipykernel/kernelapp.py", line 419, in init_extensions
extension_man.load_extension('ipywidgets')
File "[snip]/lib/python3.6/site-packages/IPython/core/extensions.py", line 86, in load_extension
if mod.__file__.startswith(self.ipython_extension_dir):
AttributeError: module 'ipywidgets' has no attribute '__file__'
It seems that the init_extensions method has an except handler for an ImportError, but the AttributeError above slips through. Relevant lines are https://github.com/ipython/ipykernel/blob/3b6d0894aa77079da306a2de0ec5087c98de08f7/ipykernel/kernelapp.py#L414-L422
```
_originally posted by @jasongrout as https://github.com/jupyter-widgets/ipywidgets/issues/1901_

To reproduce:
1. Install ipywidgets and notebook/jlab in the base environment
```bash
conda activate base
conda install nb_conda_kernels ipywidgets ipykernel jupyterlab
conda create -n envnowidgets ipykernel
```
2. Open notebook/jlab
3. Open a new notebook selecting the kernel for `envnowidgets`
4. The Kernel should fail to start because of the above error

References:
Python 3.6.9
jupyterlab 1.1.4
ipywidgets 7.5.1 (in base)
ipykernel 5.1.2

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start at ipykernel/kernelapp.py lines 414-422 and reproduce the failure with ipywidgets installed only in the base environment and a kernel environment without it. Trace the init_extensions path and verify that the envnowidgets kernel starts successfully without ipywidgets installed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
jupyter-notebook, python
Ambito
backend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.