Skip to content

Instantly share code, notes, and snippets.

@parente parente/
Last active Oct 16, 2018

What would you like to do?
Jupyter Tidbit: Kernels for text files in JupyterLab


You can associate a Console panel and kernel with a text editor in JupyterLab, and use it to execute selected code, RStudio style.

  1. Create or open a text source file in JupyterLab.
  2. Right click in the text editor panel.
  3. Click Create Console for Editor.
  4. Select a kernel matched to the programming language you want to execute in the file.
  5. Notice the Console panel that appears.
  6. Highlight one or more lines back in the text editor you'd like to run.
  7. Press Shift-Enter to execute those lines.
  8. Notice the input and output that appears in the Console.



Here's a screencast showing how to launch a kernel and console for a simple file. Click the Binder button to try this example yourself.

Screencast of attaching a kernel and console to a file in JupyterLab

Why is this useful?

You may want to develop a traditional Python (or other language) module alongside your notebooks. Attaching a kernel-plus-console to the source file allows you to iterate quickly on developing, executing, and evaluating your work without leaving the Jupyter environment or having to copy/paste code between a notebook / console and the module file.

import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(10, 10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.