---
title: Debug Databricks notebooks
description: "Debug Python notebooks in Databricks with the interactive debugger: set breakpoints, step through code, inspect variables, and use the debug console."
canonical_url: https://docs.databricks.com/aws/en/notebooks/debugger
---

# Debug Databricks notebooks

Databricks notebooks include a built-in interactive debugger, available for Python code only.

The interactive debugger provides breakpoints, step-by-step execution, variable inspection, and more tools to help you develop code in notebooks more efficiently.

## Requirements

To access the debugger, your notebook must be connected to one of the following compute resources:

* [Serverless compute](https://docs.databricks.com/aws/en/compute/serverless/notebooks.md)
* Compute with [access mode](https://docs.databricks.com/aws/en/compute/configure.md#access-mode) set to **Standard** (formerly shared) in Databricks Runtime 14.3 LTS and above
* Compute with [access mode](https://docs.databricks.com/aws/en/compute/configure.md#access-mode) set to **Dedicated** (formerly single user) in Databricks Runtime 13.3 LTS and above
* Compute with [access mode](https://docs.databricks.com/aws/en/compute/configure.md#access-mode) set to **No Isolation Shared** in Databricks Runtime 13.3 LTS and above

### Enable the debugger

Use the following steps to enable the debugger:

1. Click your username at the upper-right of the workspace and select **Settings** from the drop-down list.
2. In the **Settings** sidebar, select **Developer**.
3. In the **Editor settings** section, turn on **Python Notebook Interactive Debugger**.

## Start debugging

To start the debugger, follow these steps:

1. Add one or more breakpoints by clicking in the gutter of a cell. To remove a breakpoint, click on it again.

   ![create and remove breakpoints video](https://docs.databricks.com/aws/en/images/notebooks/breakpoints.gif)

2. Start the debugging session by using one of the following options:

   * Click **Run > Debug cell**.
   * Use the keyboard shortcut **Option + Shift + D**.
   * From the cell run menu, select **Debug cell**.

   ![debug cell item in cell run menu](https://docs.databricks.com/aws/en/images/notebooks/debug-in-cell-menu.png)

A debug session starts automatically and runs the selected cell.

You can also start the debugger if a cell triggers an error. At the bottom of the cell output, click ![Debug button](https://docs.databricks.com/aws/en/images/notebooks/debug-button.png).

When a debug session is active, the debug toolbar ![Debug toolbar](https://docs.databricks.com/aws/en/images/notebooks/debug-toolbar.png) appears at the top of the cell.

## Debugging actions

![annotated debugger toolbar](https://docs.databricks.com/aws/en/images/notebooks/debugger-toolbar.png)

In a debug session, you can do the following:

* Set or remove breakpoints.
* View the values of variables at a breakpoint.
* Step through the code.
* Step into or out of a function.
* Locate the line the debugger is stopped at.

When the code reaches a breakpoint, it stops before the line is run, not after.

Use the buttons in the debugger toolbar to step through the code. As you step through the code, the current line is highlighted in the cell. You can view variable values in the variable explorer pane in the right sidebar.

When you step through a function, local function variables appear in the variable pane, marked `[local]`.

## <a id="debugger-on-workspace-files" />Step into workspace files

You can set breakpoints and step into functions defined in other workspace files. To step into a function, click the step in icon ![Arrow down dot icon.](https://docs.databricks.com/aws/en/images/product-icons/ArrowDownDotIcon.svg). If the function is defined in another workspace file, the debugger opens that file in a new tab.

![example step in](https://docs.databricks.com/aws/en/images/notebooks/debugger-on-workspace-files-example.gif)

> [!NOTE]
>
> * The debugger can only step into functions defined in files in the workspace. Stepping into Python libraries or other notebooks is not yet supported.
> * If you edit external files after they're imported, the notebook session might still use the old version of the module. To ensure that edits to imported modules take effect during debugging, use [autoreload for Python modules](https://docs.databricks.com/aws/en/files/workspace-modules.md#autoreload-for-python-modules) in Databricks Runtime 18.0+ or serverless compute environment version 4+.

## <a id="debug-console" />Debug console

When you start a debugging session, the debug console automatically appears in the bottom panel. This console allows you to execute Python code to inspect or manipulate variables when paused at a breakpoint. Code executed in the main notebook does not run during a debugging session. To run code in the console, press **Enter**. For multi-line expressions, use **Shift + Enter** to move to a new line.

![debug\_console](https://assets.docs.databricks.com/_static/images/notebooks/debug-console.gif)

> [!NOTE]
>
> * The debug console is designed for quick evaluations and times out if the code execution exceeds 15 seconds.
> * The `display` command is not supported in the debug console. To view sample data from a DataFrame, use `df.show()` for PySpark DataFrames or `df.head()` for Pandas DataFrames.

## <a id="variable-explorer" />Variable explorer

You can use the variable explorer panel ![the variable explorer icon](https://docs.databricks.com/aws/en/images/notebooks/variable-explorer-icon.png) on the right side to view the values of your variables. Clicking **Inspect** automatically executes code in the debug console to output the value of your variable.

![example variable explorer panel](https://docs.databricks.com/aws/en/images/notebooks/variable-explorer-example.png)

To filter the display, enter text into the search box. The list is automatically filtered as you type.

For Python on Databricks Runtime 12.2 LTS and above, the variables update as a cell runs. For Scala, R, and for Python on Databricks Runtime 11.3 LTS and below, variables update after a cell finishes running.

## Terminate a debugger session

To end the debugging session, click ![debugger stop button](https://docs.databricks.com/aws/en/images/notebooks/debugger-stop.png) at the upper-left of the cell or click ![notebook stop button](https://docs.databricks.com/aws/en/images/notebooks/stop-button.png) at the top of the notebook. The debug session also automatically terminates after 30 minutes if the user does not use the debugging toolbar or debug console.

## Debug with Genie Code

Genie Code can diagnose errors and suggest fixes in your notebook code. See [Genie Code command shortcuts for notebooks](https://docs.databricks.com/aws/en/notebooks/code-assistant.md#notebook-assistant) for more information.

## Limitations

See [Known limitations of Databricks notebooks](https://docs.databricks.com/aws/en/notebooks/notebook-limitations.md) for more information.
