Search code examples
pythonvisual-studio-codejupyter-notebook

Unable to start Jupyter Notebook Kernel in VS Code


I am trying to run a Jupyter Notebook in VS Code. However, I'm getting the following error message whenever I try to execute a cell:

Failed to start the Kernel. 
Jupyter server crashed. Unable to connect. 
Error code from Jupyter: 1
usage: jupyter.py [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
                  [--paths] [--json] [--debug]
                  [subcommand]

Jupyter: Interactive Computing

positional arguments:
  subcommand     the subcommand to launch

options:
  -h, --help     show this help message and exit
  --version      show the versions of core jupyter packages and exit
  --config-dir   show Jupyter config dir
  --data-dir     show Jupyter data dir
  --runtime-dir  show Jupyter runtime dir
  --paths        show all Jupyter paths. Add --json for machine-readable
                 format.
  --json         output paths as machine-readable json
  --debug        output debug information about paths

Available subcommands:

Jupyter command `jupyter-notebook` not found. 
View Jupyter log for further details.

The Jupyter log referred to by the diagnostic message just contains the same text as the above diagnostic message repeated multiple times.

I believe this post refers to the same issue. Unfortunately, the accepted answer does not work for me because I do not have Python: Select Interpreter to Start Jupyter server in my Command Palette.

The file was working normally this morning. I also tried uninstalling and reinstalling the extensions.

How can I get the Kernel to start?


Solution

  • This sounds like it might be a bug that found in the 2023.1 version of the Jupyter extension that affects MacOS users: Starting a Jupyter server kernel fails (when zmq does not work) #12714 (duplicates: Failed to start the Kernel, version v2023.1.2000312134 #12726, Jupyter server crashed. Unable to connect. #12746) The solution recommended there was to switch to the pre-release version while waiting for the fix to come to the regular-release-channel released the fix. Others in the threads there also found that rolling back to older extension versions also worked for them (you can rollback clicking into the down menu button next to the extension's uninstall button).

    If none of those solutions work, try this:

    pip install --upgrade --force-reinstall --no-cache-dir jupyter
    

    And then restart VS Code. If you already have it open, you can do this in the VS Code command palette with the Developer: Reload Window command.

    Credit: The above command is based on this answer by @Spandana-r to the question After installing with pip, "jupyter: command not found".