Parente's Mindtrove

Jupyter Tidbit: Kernels for text files in JupyterLab

August 24, 2018

This post originates from a gist that supports comments, forks, and execution in binder.


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.

Another Read: Jupyter Tidbit: Launch Notebook on Binder without leaving your browser »

You can launch a temporary Jupyter Notebook server in the cloud with any pip or conda packaged libraries preinstalled using the GitHub Gist and Binder web UIs.