question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jupyter not respecting pre-set kernel in notebook metadata

See original GitHub issue

Environment data

  • VS Code version: 1.63.2
  • Jupyter Extension version (available under the Extensions sidebar): v2021.11.1001550889
  • Python Extension version (available under the Extensions sidebar): v2021.12.1559732655
  • OS (Windows | Mac | Linux distro) and version: Windows 10 19042.1348
  • Python and/or Anaconda version: Python 3.6.8
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Jupyter server running: Local | Remote | N/A : Both Local and Remote

Expected behaviour

Jupyter Extension respects defined kernel in the *.ipynb file metadata

Actual behaviour

For each folder I open, I must re-select the kernel before executing.

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. Create new notebook, and select kernel.
  2. Save notebook with kernel selected
  3. Move notebook to another folder
  4. Open new folder in VSCode and open the notebook.
  5. See if kernel is still selected

image

Example of notebook file in txt form after saving kernel

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

I tried to find another issue discussing this, but didn’t find an exact match.

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
greazercommented, Jan 27, 2022

After a bunch of discussion here on the team, it was decided that the current shipping behavior should remain for now. The main reasons are:

  1. When opening a new notebook that VS Code has never seen, there’s really no 100% way to know that the kernel specified in the metadata actually maps to a kernel on the user’s machine.
  2. In the above case, even though the kernel isn’t selected, it is moved to the top of the kernel picker list as the “Suggested” kernel.
  3. After a notebook has been executed within VS Code, then the kernel specified in metadata is much more likely to be the “right” one to select by default. So on subsequent re-opens of that notebook it IS set as the kernel by default.
1reaction
rchiodocommented, Jan 26, 2022

Thanks for the bug.

VS code doesn’t actually allow us to specify a specific kernel to set the first time it sees a notebook, but we can probably trick it by forcing a selection.

I’m rather surprised nobody else has logged this yet. I can’t find a dupe though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Default kernel in jupyter notebook - Stack Overflow
Open the notebook. Then navigate to Kernel -> Change Kernel and select the kernel you want to use. The question was specifically for...
Read more >
Making kernels for Jupyter — jupyter_client 7.4.8 documentation
Making kernels for Jupyter . A 'kernel' is a program that runs and introspects the user's code. IPython includes a kernel for Python...
Read more >
Working with Jupyter Notebooks in Visual Studio Code
View, inspect, and filter variables using the Variable Explorer and Data Viewer; Connect to a remote Jupyter server; Debug a Jupyter Notebook. Setting...
Read more >
The Jupyter Notebook Format — IPython 3.2.1 documentation
Jupyter (né IPython) notebook files are simple JSON documents, ... While the type and values of some metadata are defined, no metadata values...
Read more >
How to Version Control Jupyter Notebooks - Nextjournal
Jupyter notebooks generate files that may contain metadata, source code, ... The JSON data above renders the following result in Jupyter Notebook:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found