Introduction II - Jupiter Notebook 7.0#
Yury Markov
Phd student - Scene Grammar Lab
Objectives 📍#
learn new features of
jupyter notebooks 7.0
based on Notebook 7.0 documentation
Themes#
A Dark Theme is now available in the Jupyter Notebook by default. You can also install other themes as JupyterLab extensions.
Table of content#
Notebook 7 includes a new table of contents extension that allows you to navigate through your notebook using a sidebar. The Table of Contents is built-in and enabled by default, just like in JupyterLab.
New UI#
Lets look on it together in the class
What is a Debugger?#
A debugger is a tool that helps programmers find and fix errors in their code by allowing them to examine the code line-by-line as it executes. It is particularly useful for:
Identifying where and why code is failing
Inspecting variable values at different stages of execution
Testing logical flows and ensuring functions work as expected
With a debugger, you can set breakpoints (specific lines where the code will pause) to inspect the state of your program and understand how data is being processed.
How to Use the Debugger in Jupyter Notebook 7#
Jupyter Notebook 7 includes a built-in debugger, but it requires a compatible kernel (like IPython 7.0 or later or xeus-python) to function. Here’s a step-by-step guide on using the debugger:
Step 1: Select a Debugger-Compatible Kernel#
Open your notebook.
Go to the Kernel menu and select Change Kernel.
Choose a kernel compatible with debugging (e.g., IPython or xeus-python).
If you don’t see a compatible kernel, ensure you have the latest version of IPython by running:
pip install ipykernel –upgrade
Step 2: Activate the Debugger#
With a compatible kernel selected, you should see a Debugger button in the toolbar or under the View or Kernel menus.
Click the Debugger button to enable debug mode.
Step 3: Set Breakpoints#
Click in the left margin of a code cell next to the line numbers to add breakpoints. These red dots indicate where execution will pause, allowing you to inspect variables.
You can add multiple breakpoints within a cell or across cells as needed.
Step 4: Run the Debugger#
Run the cell with the breakpoints set.
The debugger will pause execution at each breakpoint, allowing you to inspect the state of variables and the code’s behavior.
Step 5: Step Through the Code#
While in debug mode, use the following options to control execution:
Continue: Resume code execution until the next breakpoint.
Step Over: Move to the next line within the current function.
Step Into: Enter into a function call to debug it line by line.
Inspect Variables: The debugger panel displays variable values, letting you inspect them at each breakpoint.
Example Code with Debugger#
def divide_numbers(a, b):
result = a / b # Set a breakpoint here to check values of 'a' and 'b'
return result
divide_numbers(10, 0) # This will throw an error due to division by zero
Exiting Debug Mode#
Once you are done debugging, you can click Stop Debugging to exit debug mode and resume regular code execution.
Troubleshooting#
If the debugger option is unavailable, ensure:
You are using Jupyter Notebook 7 or later.
You have a compatible kernel installed.
The debugger in Jupyter Notebook 7 allows you to diagnose issues within your code interactively, making it a powerful tool for troubleshooting and understanding your code.