ipython / ipython/ipykernel

Error starting an ipykernel without ipywidgets installed

Ouverte
#451 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Python
Étoiles
734
Forks
412
Merge moyen
1 j 5 h
PR mergées (30 j)
8

Description

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

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.