ipython / ipython/ipykernel

Error starting an ipykernel without ipywidgets installed

未关闭
#451 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
734
派生
412
平均合并
1 天 5 小时
30 天内合并 PR
8

描述

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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。