Visual Studio Jupyter Notebook



To create a new notebook open the command palette (Windows: Ctrl + Shift + P, iOS: Command + Shift + P) and select the command 'Jupyter: Create New Blank Notebook' Select your kernel by clicking on the kernel picker in the bottom right of the status bar or by invoking the 'Notebook: Select Notebook. Use Notebooks in Visual Studio Code VS Code is a free code editor that you can use locally or connected to remote compute. Combined with the Python extension, it offers a full environment for Python development including a rich native experience for working with Jupyter Notebooks. Jupyter (formerly IPython Notebook) is an open-source project that lets you easily combine Markdown text and executable Python source code on one canvas called a notebook. Visual Studio Code supports working with Jupyter Notebooks natively, as well as through Python code files. This topic covers the support offered through Python code files.

-->

In this article, you'll learn how to connect to an Azure Machine Learning compute instance using Visual Studio Code.

An Azure Machine Learning Compute Instance is a fully managed cloud-based workstation for data scientists and provides management and enterprise readiness capabilities for IT administrators.

There are two ways you can connect to a compute instance from Visual Studio Code:

  • Remote compute instance. This option provides you with a full-featured development environment for building your machine learning projects.
  • Remote Jupyter Notebook server. This option allows you to set a compute instance as a remote Jupyter Notebook server.

Configure a remote compute instance

To configure a remote compute instance for development, you'll need a few prerequisites.

  • Azure Machine Learning Visual Studio Code extension. For more information, see the Azure Machine Learning Visual Studio Code Extension setup guide.
  • Azure Machine Learning workspace. Use the Azure Machine Learning Visual Studio Code extension to create a new workspace if you don't already have one.
  • Azure Machine Learning compute instance. Use the Azure Machine Learning Visual Studio Code extension to create a new compute instance if you don't have one.

To connect to your remote compute instance:

Azure Machine Learning Extension

  1. In VS Code, launch the Azure Machine Learning extension.
  2. Expand the Compute instances node in your extension.
  3. Right-click the compute instance you want to connect to and select Connect to Compute Instance.

Command Palette

  1. In VS Code, open the command palette by selecting View > Command Palette.
  2. Enter into the text box Azure ML: Connect to Compute Instance.
  3. Select your subscription.
  4. Select your workspace.
  5. Select your compute instance or create a new one.

Navigate to ml.azure.com

Important

In order to connect to your remote compute instance from Visual Studio Code, make sure that the account you're logged into in Azure Machine Learning studio is the same one you use in Visual Studio Code.

Compute

  1. Select the Compute tab
  2. In the Application URI column, select VS Code for the compute instance you want to connect to.

Notebook

  1. Select the Notebook tab
  2. In the Notebook tab, select the file you want to edit.
  3. Select Editors > Edit in VS Code (preview).

A new window launches for your remote compute instance. When attempting to make a connection to a remote compute instance, the following tasks are taking place:

  1. Authorization. Some checks are performed to make sure the user attempting to make a connection is authorized to use the compute instance.
  2. VS Code Remote Server is installed on the compute instance.
  3. A WebSocket connection is established for real-time interaction.

Once the connection is established, it's persisted. A token is issued at the start of the session which gets refreshed automatically to maintain the connection with your compute instance.

After you connect to your remote compute instance, use the editor to:

  • Author and manage files on your remote compute instance or file share.
  • Use the VS Code integrated terminal to run commands and applications on your remote compute instance.

Configure compute instance as remote notebook server

In order to configure a compute instance as a remote Jupyter Notebook server you'll need a few prerequisites:

  • Azure Machine Learning Visual Studio Code extension. For more information, see the Azure Machine Learning Visual Studio Code Extension setup guide.
  • Azure Machine Learning workspace. Use the Azure Machine Learning Visual Studio Code extension to create a new workspace if you don't already have one.

To connect to a compute instance:

  1. Open a Jupyter Notebook in Visual Studio Code.

  2. When the integrated notebook experience loads, select Jupyter Server.

    Alternatively, you also use the command palette:

    1. Open the command palette by selecting View > Command Palette from the menu bar.
    2. Enter into the text box Azure ML: Connect to Compute instance Jupyter server.
  3. Choose Azure ML Compute Instances from the list of Jupyter server options.

  4. Select your subscription from the list of subscriptions. If you have have previously configured your default Azure Machine Learning workspace, this step is skipped.

  5. Select your workspace.

  6. Select your compute instance from the list. If you don't have one, select Create new Azure ML Compute Instance and follow the prompts to create one.

  7. For the changes to take effect, you have to reload Visual Studio Code.

  8. Open a Jupyter Notebook and run a cell.

Important

You MUST run a cell in order to establish the connection.

At this point, you can continue to run cells in your Jupyter Notebook.

Tip

You can also work with Python script files (.py) containing Jupyter-like code cells. For more information, see the Visual Studio Code Python interactive documentation.

Next steps

Now that you've set up Visual Studio Code Remote, you can use a compute instance as remote compute from Visual Studio Code to interactively debug your code.

Tutorial: Train your first ML model shows how to use a compute instance with an integrated notebook.

Jupyter Notebooks are documents that contain a mix of live code (Python, R, Julia, JavaScript, and more), visualizations, and narrative text (Markdown). They're useful for breaking down concepts in a story telling form, where you can give some context and show the code below along with interactive visualizations.

What do they look like in a classroom?

Below are several real life examples of how Jupyter Notebooks can be used in classrooms.

Studio

Storytelling

Notebooks can be useful for explaining large topics, piece by piece, with rich imagery and videos embedded.

Debug Jupyter Notebook Visual Studio

Here one instructor is using extra visualizations and pseudo-code to help students code their merge sort implementation.

This Is What I Believe They Mean With Download As. You Need The Notebook Running Then Click On File-> Download As-> Pythong(.py ). Http://imgur.co...

This instructor is explaining how time complexities work broken down with tables of data, graphs, explanations, and code:

Visual Studio Code Python Jupyter

It's also a great way to see and compare the exact runtimes of code blocks, which can be very helpful for learning data structures and algorithm fundamentals.

Interactive output

Jupyter Notebooks can also have rich interactive outputs. The instructor below is creating a Notebook for a lecture about the maximum flow problem and utilizing the pyviz library to make an interactive network graph to visualize the problem description. They are also utilizing the built-in LaTeX support to show mathematical symbols for the problem constraints.

Rich assignments

They are also a great format for handing out assignments. Here an instructor created an assignment to teach Binary Search Trees that includes a mix of students needing to implement code and write long form written responses to theoretical questions.

Getting started

You will need to have Python 3 installed on your machine along with the Microsoft Python extension installed from the VS Code Marketplace. You can review the introductory Python tutorial for help with setup.

In addition, you need to install the Jupyter Notebooks extension.

Once you have Python and the extensions installed, you will need to activate the Python environment by using the command Python: Select Interpreter from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).

For full instructions on how to use Jupyter Notebooks, follow the step by step Jupyter Notebook guide.

@Jonathan Answer Is Correct. The MSDN Blog Was Referring To Jupyter Notebooks Menu Item File->Download->Python (.py). There's Additional Considerat...