Table of Contents
What are Notebooks?
Notebooks are documents that combine live code, equations, visualizations, and narrative text into a single canvas. They allow you to create and share documents that tell a data story.
The most popular notebook format is Jupyter Notebook, which supports over 100 programming languages including Python, R, Julia, and Scala.
Why Use Notebooks in VS Code?
Visual Studio Code provides excellent support for working with Jupyter Notebooks:
- Full featured text editor to easily edit code and markdown cells
- Built-in terminal and git support
- Extensible and customizable via the Extension Marketplace
- Local or remote compute connections
- Available on Windows, macOS, and Linux
Some key benefits include:
- Code Editing – Take advantage of VS Code’s great code editing support including IntelliSense, linting, formatting, etc.
- Version Control – Easily commit your notebooks to git and collaborate.
- Customizability – Install extensions to customize the notebooks experience.
- Flexible Computing – Connect and offload compute to remote machines or cloud services.
Install the Extensions
To work with Jupyter Notebooks in VS Code, you need to install 2 extensions:
- Python – Provides overall support for Python including Jupyter Notebook functionality.
- Jupyter – Extends notebook support for other kernels like R and Julia.
To install:
- Open the Extensions view (
Ctrl+Shift+X
) - Search for
python
and install the Python extension by Microsoft - Search for
jupyter
and install the Jupyter extension by Microsoft
The Jupyter extension will be installed automatically with the Python extension, so you only need to explicitly install Python.
Create a New Notebook
There are two ways to create a Jupyter Notebook:
- Command Palette:
Ctrl+Shift+P
to open the command palette- Start typing “create new blank notebook” and select that option
- New File:
- Click the New File button on the File Explorer
- Select Jupyter Notebook
After selecting a kernel, a new notebook will open with the first blank code cell.
Working with Code Cells
You can now add Markdown and Code cells:
- Add cell – Click
+ Code
or+ Markdown
on the top toolbar - Run cell – Click the
Run Cell
icon on the left toolbar - Advanced run – Shift+Enter runs and advances, Ctrl+Enter runs just current cell
Use keyboard shortcuts to edit cells:
Ctrl+M m
– Toggle cell to MarkdownCtrl+M y
– Toggle cell to CodeAlt+Up
– Move cell upAlt+Down
– Move cell downShift+Enter
– Run cell and advance
Additional Tips
Here are some additional tips for working with Jupyter Notebooks in VS Code:
- Install the Markdown All in One and Rainbow CSV extensions for enhanced Markdown editing
- Enable Auto Save to automatically save your notebook
- Reference the Jupyter Cheat Sheet extension for handy keyboard shortcuts
- For Python, install related extensions like Pylance and Jupyter Keymap
- Use the built-in Version Control and Git support
Summary
Visual Studio Code provides a robust environment for working with Jupyter Notebooks. The Python and Jupyter extensions enable first-class support for editing code, markdown, parameters, visualizations, and more in notebook documents. Additional VS Code functionality like version control and customizability through extensions further enhances the experience.