jupyter-server / jupyter_server

The backend—i.e. core services, APIs, and REST endpoints—to Jupyter web applications.
https://jupyter-server.readthedocs.io
BSD 3-Clause "New" or "Revised" License
493 stars 308 forks source link

Launching a kernel fails depending on folder contents #327

Closed akhmerov closed 4 years ago

akhmerov commented 4 years ago

It seems that jupyter will fail to launch new kernels if there's a name collision with e.g. a module in stdlib in the notebook folder. To observe this behavior:

  1. Launch a jupyterlab binder (but I think anything else would work the same) or run sudo docker run --rm -it -p 8888:8888 jupyter/base-notebook
  2. Create an empty file email.py in the notebook folder e.g. by executing !touch email.py in a new cell.
  3. Observe that restarting the kernel fails to bring it back and launching a new console doesn't work.

In local logs I see the following

traceback ``` Traceback (most recent call last): File "/opt/conda/lib/python3.8/runpy.py", line 194, in _run_module_as_main return _run_code(code, main_globals, None, File "/opt/conda/lib/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/opt/conda/lib/python3.8/site-packages/ipykernel_launcher.py", line 15, in from ipykernel import kernelapp as app File "/opt/conda/lib/python3.8/site-packages/ipykernel/__init__.py", line 2, in from .connect import * File "/opt/conda/lib/python3.8/site-packages/ipykernel/connect.py", line 13, in from IPython.core.profiledir import ProfileDir File "/opt/conda/lib/python3.8/site-packages/IPython/__init__.py", line 56, in from .terminal.embed import embed File "/opt/conda/lib/python3.8/site-packages/IPython/terminal/embed.py", line 17, in from IPython.terminal.ipapp import load_default_config File "/opt/conda/lib/python3.8/site-packages/IPython/terminal/ipapp.py", line 28, in from IPython.core.magics import ( File "/opt/conda/lib/python3.8/site-packages/IPython/core/magics/__init__.py", line 18, in from .code import CodeMagics, MacroToEdit File "/opt/conda/lib/python3.8/site-packages/IPython/core/magics/code.py", line 23, in from urllib.request import urlopen File "/opt/conda/lib/python3.8/urllib/request.py", line 88, in import http.client File "/opt/conda/lib/python3.8/http/client.py", line 71, in import email.parser ModuleNotFoundError: No module named 'email.parser'; 'email' is not a package ```

I believe that this behavior us confusing to the users and undesirable.

Apologies if this is a wrong repository for the issue and/or if the issue has already been reported.

kevin-bates commented 4 years ago

Hi @akhmerov - this is a fairly well-known issue inherent in the IPython/ipykernel machinery and python scoping. There are several instances of this (with varying filenames involved), but here's the "most root" issue I find: https://github.com/ipython/ipykernel/issues/112.

I would suggest "namespacing" local files with a common prefix or something of that sort.

Since this isn't related to this repository (more of a kernel issue), I'm going ahead and closing the issue here.