Looking for help with a Kernel error

Hi ! I hope this is the right place to ask this, sorry if this isn’t, I’m fairly new to all of this.
Just like I said i’m quite new to programmation overall. I’m a student and I need to install Jupyter for some engineering projects especially.
I am on MacOS catalina and I tried to install it first via homebrew and then using anaconda. It seemed to install correctly both times. However, whenever I try to execute any code it just switches to a new cell without executing the code, like this:

Beside, I get a Kernel error (I guess it has something to do with this issue) and i’m not experienced enough to really know what it implies so I hope someone could help me out, thanks !

Here’s the error:

  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1699, in _execute
    result = await result
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/handlers.py", line 72, in post
    type=mtype))
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 88, in create_session
    kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 101, in start_kernel_for_session
    self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/kernels/kernelmanager.py", line 168, in start_kernel
    super(MappingKernelManager, self).start_kernel(**kwargs)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
    km.start_kernel(**kwargs)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 259, in start_kernel
    **kw)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
    return launch_kernel(kernel_cmd, **kw)
  File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/launcher.py", line 138, in launch_kernel
    proc = Popen(cmd, **kwargs)
  File "/Users/alexandre/anaconda3/lib/python3.7/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/Users/alexandre/anaconda3/lib/python3.7/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/alexandre/my_environment_name/bin/python': '/Users/alexandre/my_environment_name/bin/python'

Have you checked the paths provided in the error messages? Is the file at that path really missing? Can you start the python interpreter for the given environment from the terminal?

The file seems to not actually be missing:

Here’s the what the terminal gives me:

[I 00:29:16.992 NotebookApp] JupyterLab application directory is /Users/alexandre/anaconda3/share/jupyter/lab
[I 00:29:17.215 NotebookApp] Serving notebooks from local directory: /Users/alexandre
[I 00:29:17.215 NotebookApp] The Jupyter Notebook is running at:
[I 00:29:17.216 NotebookApp] http://localhost:8888/?token=72323ccad1371db04783fb330f3dd5dbfd98d7d7108f1a24
[I 00:29:17.216 NotebookApp]  or http://127.0.0.1:8888/?token=72323ccad1371db04783fb330f3dd5dbfd98d7d7108f1a24
[I 00:29:17.216 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 00:29:17.224 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///Users/alexandre/Library/Jupyter/runtime/nbserver-25131-open.html
    Or copy and paste one of these URLs:
        http://localhost:8888/?token=72323ccad1371db04783fb330f3dd5dbfd98d7d7108f1a24
     or http://127.0.0.1:8888/?token=72323ccad1371db04783fb330f3dd5dbfd98d7d7108f1a24
[I 00:29:58.933 NotebookApp] Creating new directory in /Desktop/Scolaire/MPSI/SII
[I 00:30:06.236 NotebookApp] Creating new notebook in /Desktop/Scolaire/MPSI/SII/Untitled Folder
[E 00:30:07.037 NotebookApp] Failed to run command:
    ['/Users/alexandre/my_environment_name/bin/python', '-m', 'ipykernel_launcher', '-f', '/Users/alexandre/Library/Jupyter/runtime/kernel-50c74568-bfae-45c8-82f6-2d914736965d.json']
        PATH='/Users/alexandre/anaconda3/bin:/Users/alexandre/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/Wireshark.app/Contents/MacOS'
        with kwargs:
    {'stdin': -1, 'stdout': None, 'stderr': None, 'cwd': '/Users/alexandre/Desktop/Scolaire/MPSI/SII/Untitled Folder', 'start_new_session': True}

[E 00:30:07.038 NotebookApp] Uncaught exception POST /api/sessions (::1)
    HTTPServerRequest(protocol='http', host='localhost:8888', method='POST', uri='/api/sessions', version='HTTP/1.1', remote_ip='::1')
    Traceback (most recent call last):
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/web.py", line 1699, in _execute
        result = await result
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/handlers.py", line 72, in post
        type=mtype))
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
        value = future.result()
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 88, in create_session
        kernel_id = yield self.start_kernel_for_session(session_id, path, name, type, kernel_name)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
        value = future.result()
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 742, in run
        yielded = self.gen.throw(*exc_info)  # type: ignore
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/sessions/sessionmanager.py", line 101, in start_kernel_for_session
        self.kernel_manager.start_kernel(path=kernel_path, kernel_name=kernel_name)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 735, in run
        value = future.result()
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/tornado/gen.py", line 209, in wrapper
        yielded = next(result)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/notebook/services/kernels/kernelmanager.py", line 168, in start_kernel
        super(MappingKernelManager, self).start_kernel(**kwargs)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/multikernelmanager.py", line 110, in start_kernel
        km.start_kernel(**kwargs)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 259, in start_kernel
        **kw)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/manager.py", line 204, in _launch_kernel
        return launch_kernel(kernel_cmd, **kw)
      File "/Users/alexandre/anaconda3/lib/python3.7/site-packages/jupyter_client/launcher.py", line 138, in launch_kernel
        proc = Popen(cmd, **kwargs)
      File "/Users/alexandre/anaconda3/lib/python3.7/subprocess.py", line 800, in __init__
        restore_signals, start_new_session)
      File "/Users/alexandre/anaconda3/lib/python3.7/subprocess.py", line 1551, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/alexandre/my_environment_name/bin/python': '/Users/alexandre/my_environment_name/bin/python'
[W 00:30:07.056 NotebookApp] Unhandled error
[E 00:30:07.057 NotebookApp] {
      "Host": "localhost:8888",
      "Connection": "keep-alive",
      "Content-Length": "133",
      "Accept": "application/json, text/javascript, */*; q=0.01",
      "X-Requested-With": "XMLHttpRequest",
      "X-Xsrftoken": "2|cad8aadc|e9f6cf57b59c107cca85976a7ca49077|1590082265",
      "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36",
      "Content-Type": "application/json",
      "Origin": "http://localhost:8888",
      "Sec-Fetch-Site": "same-origin",
      "Sec-Fetch-Mode": "cors",
      "Sec-Fetch-Dest": "empty",
      "Referer": "http://localhost:8888/notebooks/Desktop/Scolaire/MPSI/SII/Untitled%20Folder/Untitled.ipynb?kernel_name=python3",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
      "Cookie": "_xsrf=2|cad8aadc|e9f6cf57b59c107cca85976a7ca49077|1590082265; username-localhost-8889=\"2|1:0|10:1590279034|23:username-localhost-8889|44:ZThiMTU2OTM5ZWY1NGM5ZGI3Y2MxNTZmOTM1ZmFlZDk=|9d5dd3fd595ba0da90a8a427ad4f7afef63aa546092c1dbafc15d3605db607dd\"; username-localhost-8888=\"2|1:0|10:1590445758|23:username-localhost-8888|44:NmE4NjU5NGYzOGViNGQyZGFkOWY2YWI3NWMxNWUzZmI=|7172d0a74b6147cfe291e613434f1808d896f5e2039b3b8b2555b88639d9ad27\""
    }
[E 00:30:07.061 NotebookApp] 500 POST /api/sessions (::1) 102.75ms referer=http://localhost:8888/notebooks/Desktop/Scolaire/MPSI/SII/Untitled%20Folder/Untitled.ipynb?kernel_name=python3
[I 00:32:06.980 NotebookApp] Saving file at /Desktop/Scolaire/MPSI/SII/Untitled Folder/Untitled.ipynb
[I 00:34:06.975 NotebookApp] Saving file at /Desktop/Scolaire/MPSI/SII/Untitled Folder/Untitled.ipynb

The issue indeed seems to come from this particular file, I ran jupyter kernelspec list --json and it returns

  "kernelspecs": {
    "python3": {
      "resource_dir": "/Users/alexandre/Library/Jupyter/kernels/python3",
      "spec": {
        "argv": [
          "/Users/alexandre/my_environment_name/bin/python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {}
      }
    }
  }
}

It might help… Thank you :slight_smile:

If the file actually exists, maybe it is about broken permissions? But now I also just start guessing. Maybe somebody else has an idea as well?

I think you have an old kernelspec pointing to an environment that doesn’t exist anymore, in your user directory, which has higher priority than a given Python installation’s default. You can remove this with:

jupyter kernelspec remove python3

which should give you a confirmation like:

Kernel specs to remove:
  python3             	/Users/alexandre/Library/Jupyter/kernels/python3
Remove 1 kernel specs [y/N]

After this, if you run jupyter kernelspec list you should see an entry for python3 in your environment, like:

Available kernels:
  python3      /Users/alexandre/anaconda3/share/jupyter/kernels/python3

If you don’t see that, you can recreate it with:

ipython kernel install --sys-prefix
3 Likes

It worked, thank you ! I scrapped my whole python installation and re-did it to get a fresh start last week, I guess there were some leftovers

1 Like

hello i have a problem with the kernell of my Jupyterhub :

Thank you so much for this solution. I’ve been experiencing problems like this which popped up here and there for the past year and has been so frustrating. This completely fixed my problems. Seriously, thank you so much! From one internet stranger to another - you are a true hero.

1 Like