Visual Studio Code Jupyter



-->

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.

Working with Jupyter Notebooks in Visual Studio Code 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. Search results for 'jupyter', Visual Studio Code on marketplace.visualstudio.com. This package requires Visual Studio Code 1.56.0-insider or newer. This discussion is only about Visual Studio Jupyter VSCode Extension and the Visual Studio Jupyter VSCode Extension package. If you have feedback for Chocolatey, please contact the Google Group. Extension for Visual Studio Code - An easy to use extension for previewing Jupyter Notebooks within VS Code. Open a Jupyter Notebook in Visual Studio Code. When the integrated notebook experience loads, select Jupyter Server. Alternatively, you also use the command palette: Open the command palette by selecting View Command Palette from the menu bar.

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

Studio
  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

Visual Studio Code JupyterStudio

Important

Visual Studio Code Jupyter

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:

Visual Studio Code Jupyter Show Line Numbers

  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:

Visual Studio Code Jupyter
  • 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.
Visual Studio Code Jupyter

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.