ipython / ipython/ipykernel

Error starting an ipykernel without ipywidgets installed

Abierto
#451 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
734
Forks
412
Merge medio
1 d 5 h
PR fusionados (30 d)
8

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.