Instantly share code, notes, and snippets.

@parente /README.md
Last active Oct 16, 2018

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

Summary

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.

Example

Binder

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

Screencast of attaching a kernel and console to a tryit.py 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.

numpy
pandas
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randn(10, 10))
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment