Skip to content

%notebook should populate notebook metadata with language and kernel information #14954

@krassowski

Description

@krassowski

#14780 released in IPython 9.1 added support for saving outputs when exporting a notebook from IPython session:

Image

However, the exported notebooks are not properly syntax-highlighted when first opened in JupyterLab or Notebook:

Image

because the metadata does not include the langauge_info:

Image

Additionally the "select kernel" dialog shows up, suggesting potentially irrelevant kernels (if kernels other than ipykernel are installed):

Image

We should pre-populate the metadata with language_info reflecting the Python version used by IPython, and potentially with kernelspec too:

 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.11.4"
  }
 },

I think that hard-coding display_name to "Python 3 (ipykernel)" and name to python3 makes sense for now, but we could also explore how to get the "default" kernelspec if ipykernel is installed (but we should make no assumption about its availability on the machine where ipython is executing!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions