Jupyter/IPython Notebooks: Shortcut for “run all”?

后端 未结 6 1058
一整个雨季
一整个雨季 2020-12-22 20:23

Is there a shortcut to run all cells in an IPython notebook?

And if not, does this have a specific reason?

相关标签:
6条回答
  • 2020-12-22 20:50

    For the latest jupyter notebook, (version 5) you can go to the 'help' tab in the top of the notebook and then select the option 'edit keyboard shortcuts' and add in your own customized shortcut for the 'run all' function.

    0 讨论(0)
  • 2020-12-22 20:56

    Easiest solution:

    Esc, Ctrl-A, Shift-Enter.

    0 讨论(0)
  • 2020-12-22 21:02

    I've been trying to do this in Jupyter Lab so thought it might be useful to post the answer here. You can find the shortcuts in settings and also add your own, where a full list of the possible shortcuts can be found here.

    For example, I added my own shortcut to run all cells. In Jupyter Lab, under Settings > Advanced Settings, select Keyboard Shortcuts, then add the following code to 'User Overrides':

    {
        "notebook:run-all-cells": {
          "command": "notebook:run-all-cells",
          "keys": [
            "Shift Backspace"
          ],
          "selector": ".jp-Notebook.jp-mod-editMode"
        }
    }
    

    Here, Shift + Backspace will run all cells in the notebook.

    0 讨论(0)
  • 2020-12-22 21:07

    Jupyter Lab 1.0.4:

    1. In the top menu, go to: Settings->Advanced Settings Editor->Keyboard Shortcuts

    2. Paste this code in the User Preferences window:

    {
        "shortcuts": [
            {
                "command": "runmenu:run-all",
                "keys": [
                    "R",
                    "R"
                ],
                "selector": "[data-jp-kernel-user]:focus"
            }
        ]
    }
    
    1. Save (top right of the user-preferences window)

    This will be effective immediately. Here, two consecutive 'R' presses runs all cells (just like two '0' for kernel restart). Notably, system defaults has empty templates for all menu commands, including this code (search for run-all). The selector was copied from kernelmenu:restart, to allow printing r within cells. This system defaults copy-paste can be generalized to any command.

    0 讨论(0)
  • There is a menu shortcut to run all cells under Cell > "Run All". This isn't bound to a keyboard shortcut by default- you'll have to define your own custom binding from within the notebook, as described here.

    For example, to add a keyboard binding that lets you run all the cells in a notebook, you can insert this in a cell:

    %%javascript
    
    Jupyter.keyboard_manager.command_shortcuts.add_shortcut('r', {
        help : 'run all cells',
        help_index : 'zz',
        handler : function (event) {
            IPython.notebook.execute_all_cells();
            return false;
        }}
    );
    

    If you run this code from within iPython notebook, you should find that you now have a keyboard binding to run all cells (in this case, press ctrl-M followed by r)

    0 讨论(0)
  • 2020-12-22 21:12

    As of 5.5 you can run Kernel > Restart and Run All

    0 讨论(0)
提交回复
热议问题