3

I was working on a long Jupyter notebook and for some reason I had to close it and restart. After that, I'd like to run all the code before the line I was working on. Is there a convenient way to do this?

qazwsx
  • 25,536
  • 30
  • 72
  • 106
  • Possible duplicate: https://stackoverflow.com/questions/32267540/ipython-jupyter-can-we-program-a-run-all-cell-above – wbadart Jul 26 '17 at 21:18

3 Answers3

4

Click on the cell you want to run above, go to Cell -> Run All Above

Adam Hughes
  • 14,601
  • 12
  • 83
  • 122
2

You can select the relevant cells to run and then use the shortcut Control-Enter or Shift-Enter. To select the cells, choose the first one and hit esc to ensure you are not in edit mode (the color to the left should be blue, not green). Then just hold down shift and press either the up arrow or down arrow to select a range of continuous cells.

enter image description here

You could also insert a cell at your break location end enter something that will give an error, e.g. 1 / 0. The run all cells (Cell > Run All)

Alexander
  • 105,104
  • 32
  • 201
  • 196
  • This is practical only when the cells to select and run is not too many, say less than a couple of screenful. – qazwsx Jul 26 '17 at 22:52
  • You can still select them using your mouse and the scroll window on your browser. Select the first cell (hit escape to ensure that there is a blue indicator on the left to indicate you are not editing the cell). Use your scroll window to locate the ending cell (could be hundreds or thousands of cells down). Hold `Shift` while clicking the ending cell (click outside of the cell just to the left of it, by `In [ ]`. The entire range will then be selected. – Alexander Jul 26 '17 at 22:57
  • Upvoting because it's a gif – Adam Hughes Jul 27 '17 at 13:14
0

just add a cell and paste these lines of code at the point to which you want all cells to run and run this cell, all above cells will run automatically one by one.

from IPython.display import Javascript
display(Javascript('IPython.notebook.execute_cells_above()'))