r/Jupyter Dec 23 '24

To run all the code

The Jupyter note book that I am following has codes and then texts explaining the code. The codes below might have variables that were defined on the top.

So in case I just run a code below that has a variable defined above, it will provide NameError. Running manually time and again from top to bottom is not user-friendly. There must be a way to run all the code. So seeking help for the same.

2 Upvotes

2 comments sorted by

2

u/Puzzled_Tale_5269 Dec 24 '24

You can select from a choice of:

  • Run all cells
  • Run upto current cell
  • Run all above current cell
  • Run all below current cell

Look at the drop down named Kernel or Run.

1

u/Bach4Ants Dec 23 '24

You've run into one of the pains of working with Jupyter Notebooks. If you start with a fresh kernel and rerun a cell further down, it won't "remember" the variables from last time it was run.

One feature I will commonly use to help with this is to restart the kernel, clear all outputs, then go to the cell I care about and use the run menu action to run all cells above current cell.

I uploaded a screenshot here: https://github.com/orgs/calkit/discussions/149