Using Jupyter Notebook in VS Code
VS Code (full name Visual Studio Code) is a free, open-source, cross-platform code editor released by Microsoft.
Install an extension to use Jupyter Notebook in VS Code; VS Code's powerful code completion combines perfectly with Jupyter's interactive experience.
If you have not installed VS Code yet, go to itsOfficial Websiteto download and install it; the installation is very simple, just keep clicking "Next".
If you are not familiar with VS Code, see our VSCode Tutorial.
Open VS Code, click the Extensions icon in the activity bar on the left (shortcut Ctrl+Shift+X), search for and install the "Jupyter" extension (provided by Microsoft); installing it also installs the Python extension automatically.

Core features and operation guide
Create your first Jupyter Notebook
Now let us create a brand-new Jupyter Notebook file (.ipynb).
**New file:** simply create a file whose name ends in .ipynb.

You can also create it from the Command Palette:
- In VS Code, press
Ctrl+Shift+POpenCommand Palette(this is a universal search box). - Input
Jupyter: Create New Jupyter Notebookand select it. - VS Code automatically creates a file named
Untitled-1.ipynband opens it in the notebook interface. You will see the first cell is ready.

Configure the runtime environment (Kernel)
Before running code, you need to tell VS Code which Python interpreter to use:
- Click "Select Kernel" in the upper right of the editing interface.

- In the popup list, choose your installed Python version or Anaconda environment (for example Python 3.x.x or base (conda)).

- Note: on the first run, VS Code may prompt you to install the ipykernel package; just click "Install".
Then you can start writing and running code:

Running and managing cells
Run a code cell
- Run a single block: click the Play icon (▶).
- Shortcut options:
Ctrl + Enter: run the current cell.Shift + Enter: run the current cell andjump to / selectthe cell below.Alt + Enter: run the current cell andinserta new cell below.

- Run multiple blocks: use the "double arrow" icon on the top toolbar Run All to run everything; or at a specific cell choose Run Above(Run All Above) or Run Below(Run All Below).
- Run by section: in the "Outline" view, click the button next to a section heading to run the whole group of cells under that Markdown heading.

Cell modes
Cells in VS Code have three states, marked by thevertical baron the left:
- Not selected: no vertical bar.
- Command Mode: the vertical bar is solid, and keyboard commands (such as delete and copy) are available.
Enterenters Edit Mode;Escreturns to Command Mode.Ainserts a cell above;Binserts one below.D, D(press twice) deletes a cell;Zundoes a deletion.
- Edit Mode: the vertical bar is solid and the cell has a border, so you can type code.
Format switching
- In Command Mode: press
Mto switch to Markdown (document), pressYto switch to Code.
File operations and navigation
- Save:
Ctrl + S. - Export: click the
...> Exporton the toolbar. Supports exporting to.pya script, HTML or PDF (note: PDF export requires a TeX environment). - Outline navigation: jump quickly through the Outline view in the sidebar. By default only Markdown headings are shown; you can enable
Notebook > Outline: Show Code Cellsin the settings to show code blocks. - Line number control: in Command Mode, press
Lto toggle line numbers for a single cell, pressShift + Lto toggle line numbers for the whole document.

Data science enhancement tools
Variable explorer and data viewer
Click the Variables icon on the toolbar to open the variables panel at the bottom.
- View details: double-click a variable or click the icon beside it to enter the Data Viewer(data viewer).
- Filter data: type in the text box at the top of a column to search; enter
=for an exact match; regular expression filters are supported.


Saving charts
Hover over a generated chart (for example one produced by matplotlib) and click the Save icon in the upper right to save it as an image.

Debugging and advanced features
Debugging
- Run by Line: click the icon on the cell toolbar to step through code without interruption.

- Full debugging: set a breakpoint on the left of a cell and choose
Runnext to the button Debug Cell.
Remote connection
If you need the computing power of a remote server:
- click the Kernel Picker(kernel selector) in the upper right.

- Choice Existing Jupyter Server.

- Enter a server URL containing
?token=to connect.
Diff comparison
Because .ipynb is essentially JSON, and VS Code provides avisual comparison tool. You can clearly see the exact changes to inputs, outputs or metadata without reading messy raw code.
