nteract/papermill

kernel_name argument of papermill.execute seems to have no effect.

Open

#856 建立於 2025年12月17日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)Python (5,381 star) (402 fork)batch import
bughelp wanted

描述

🐛 Bug

The kernel_name argument of papermill.execute seems to have no effect. The executing notebook uses the Jupyter kernel specified in the original notebook's metatdata. Using papermill v2.6.0. Or at least the display_name in the metadata is unchanged, this is what jupyter hub uses to display the name of the kernal being used.

Something along the lines of this function should fix this:

import nbformat as nbf

def change_notebook_kernel(input_path, output_path, kernel):
    """
    Change a Jupyter Notebook's kernel.

    Parameters
    ----------
    input_path: str
        Path to the input notebook.
    output_path: str
        Path to the output notebook.
    kernel: str
        Name of the kernel_name to change to.
    """
    notebook = nbf.read(input_path, as_version=4)
    notebook['metadata']['kernelspec']['name'] = kernel
    notebook['metadata']['kernelspec']['display_name'] = kernel
    nbf.write(notebook, output_path)

貢獻者指南

kernel_name argument of papermill.execute seems to have no effect. · nteract/papermill#856 | Good First Issue