Working With Jupyter Notebooks in Visual Studio Code
Working With Jupyter Notebooks in Visual Studio Code
Once the appropriate environment is activated, you can create and open a Jupyter Notebook, connect to a
remote Jupyter server for running code cells, and export a Jupyter Notebook as a Python file.
Workspace Trust
When getting started with Notebooks, you'll want to make sure that you are working in a trusted workspace.
Harmful code can be embedded in notebooks and the Workspace Trust feature allows you to indicate which
folders and their contents should allow or restrict automatic code execution.
If you attempt to open a notebook when VS Code is in an untrusted workspace running Restricted Mode, you will
not be able to execute cells and rich outputs will be hidden.
Next, select a kernel using the kernel picker in the top right.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 1/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
After selecting a kernel, the language picker located in the bottom right of each code cell will automatically
update to the language supported by the kernel.
If you have an existing Jupyter Notebook, you can open it by right-clicking on the file and opening with VS Code,
or through the VS Code File Explorer.
Running cells
Once you have a Notebook, you can run a code cell using the Run icon to the left of the cell and the output will
appear directly below the code cell.
You can also use keyboard shortcuts to run code. When in command or edit mode, use Ctrl+Enter to run the
current cell or Shift+Enter to run the current cell and advance to the next.
You can run multiple cells by selecting Run All, Run All Above, or Run All Below.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 2/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
Note: For PDF export, you must have TeX installed. If you
don't, you will be notified that you need to install it when
you select the PDF option. Also, be aware that if you have
SVG-only output in your Notebook, they will not be
displayed in the PDF. To have SVG graphics in a PDF,
either ensure that your output includes a non-SVG image
format or else you can first export to HTML and then save
as PDF using your browser.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 3/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
When a cell is selected, it can be in two different modes. It can be in command mode or in edit mode. When the
cell is in command mode, it can be operated on and accept keyboard commands. When the cell is in edit mode,
the cell's contents (code or Markdown) can be modified.
When a cell is in command mode, a solid vertical bar will appear to the left of the cell.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 4/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
When you're in edit mode, the solid vertical bar is joined by a border around the cell editor.
To move from edit mode to command mode, press the Esc key. To move from command mode to edit mode,
press the Enter key. You can also use the mouse to change the mode by clicking the vertical bar to the left of
the cell or out of the code/Markdown region in the code cell.
Using the plus icons in the main toolbar and a cell's hover toolbar will add a new cell directly below the currently
selected cell.
When a code cell is in command mode, the A key can be used to add a cell above and the B can be used to
add a cell below the selected cell.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 5/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 6/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
You can also use keyboard shortcuts to run a selected code cell. Ctrl+Enter runs the currently selected
cell, Shift+Enter runs the currently selected cell and inserts a new cell immediately below (focus moves to new
cell), and Alt+Enter runs the currently selected cell and inserts a new cell immediately below (focus remains on
current cell). These keyboard shortcuts can be used in both command and edit modes.
To move multiple cells, you can use the same drag and drop areas in any cell included in the selection.
You can also use the keyboard shortcuts Alt+Arrow to move one or multiple selected cells.
Deleting a code cell can be accomplished by using the Delete icon in the code cell toolbar or through the
keyboard shortcut dd when the selected code cell is in command mode.
You can also use the keyboard to change the cell type. When a cell is selected and in command mode, the M key
switches the cell type to Markdown and the Y key switches the cell type to code.
Once Markdown is set, you can enter Markdown formatted content to the code cell.
To render Markdown cells, you can select the check mark in the cell toolbar, or use
the Ctrl+Enter and Shift+Enter keyboard shortcuts.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 8/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
To toggle line numbering for the entire notebook, use Shift+L when in command mode on any cell.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 9/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
Table of Contents
To navigate through your notebook, open the File Explorer in the Activity bar. Then open the Outline tab in the
Side bar.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 10/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 11/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
Data Viewer
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 12/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
For additional information about your variables, you can also double-click on a row or use the Show variable in
data viewer button next to the variable for a more detailed view of a variable in the Data Viewer.
Filtering rows
Filtering rows in the data viewer can be done by typing in the textbox at the top of each column. Type a string
you want to search for and any row that has that string in the column will be found:
If you want to find an exact match, prefix your filter with '=':
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 13/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
Saving plots
To save a plot from your notebook, simply hover over the output and select the Save icon in the top right.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 14/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
You can even customize what types of changes you want displayed within your diffing view. In the top right,
select the overflow menu item in the toolbar to customize what cell components you want included. Input
differences will always be shown.
To learn more about Git integration within VS Code, visit Version Control in VS Code.
Run by Line
Run by Line lets you execute a cell one line at a time, without being distracted by other VS Code debug features.
To start, select the Run by Line button in the cell toolbar:
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 15/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
Use the same button to advance by one statement. You can select the cell Stop button to stop early, or
the Continue button in the toolbar to continue running to the end of the cell.
Debug Cell
If you want to use the full set of debugging features supported in VS Code, such as breakpoints and the ability to
step in to other cells and modules, you can use the full VS Code debugger.
1. Start by setting any breakpoints you need by clicking in the left margin of a notebook cell.
2. Then select the Debug Cell button in the menu next to the Run button. This will run the cell in a debug
session, and will pause on your breakpoints in any code that runs, even if it is in a different cell or
a .py file.
3. You can use the Debug view, Debug Console, and all the buttons in the Debug Toolbar as you normally
would in VS Code.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 16/17
2022. 08. 09. 22:05 Working with Jupyter Notebooks in Visual Studio Code
1. Select the Jupyter Server: local button in the global Status bar or run the Jupyter: Specify local or remote
Jupyter server for connections command from the Command Palette ( Ctrl+Shift+P ).
2. When prompted to Pick how to connect to Jupyter, select Existing: Specify the URI of an existing server.
3. When prompted to Enter the URI of a Jupyter server, provide the server's URI (hostname) with the
authentication token included with a ?token= URL parameter. (If you start the server in the VS Code
terminal with an authentication token enabled, the URL with the token typically appears in the terminal
output from where you can copy it.) Alternatively, you can specify a username and password after
providing the URI.
https://code.visualstudio.com/docs/datascience/jupyter-notebooks 17/17