Set up a lab to teach data science with Python and Jupyter Notebooks


This article references features available since the August 2022 Update, when lab plans replaced lab accounts. For more information, see What's New in the August 2022 Update.

This article outlines how to set up a template virtual machine (VM) in Azure Lab Services with the tools for teaching students to use Jupyter Notebooks. You also learn how to lab users can connect to notebooks on their virtual machines.

Jupyter Notebooks is an open-source project that enables you to easily combine rich text and executable Python source code on a single canvas, known as a notebook. Running a notebook results in a linear record of inputs and outputs. Those outputs can include text, tables of information, scatter plots, and more.

Lab configuration

To set up this lab, you need access to an Azure subscription. Discuss with your organization's administrator to see if you can get access to an existing Azure subscription. If you don't have an Azure subscription, create a free account before you begin.

Lab plan settings

Once you have an Azure subscription, you can create a new lab plan in Azure Lab Services. For more information about creating a new lab plan, see Quickstart: Set up resources to create labs. You can also use an existing lab plan.

This lab uses one of the Data Science Virtual Machine Azure Marketplace images as the base VM image. You first need to enable these images in your lab plan. This lets lab creators then select the image as a base image for their lab.

  1. Follow these steps to enable these Azure Marketplace images available to lab creators. Select one of the following Azure Marketplace images, depending on your OS requirements:

    • Data Science Virtual Machine – Windows Server 2019
    • Data Science Virtual Machine – Ubuntu 18.04
  2. Alternately, create a custom VM image:

    The Data Science VMs images in the Azure Marketplace are already configured with Jupyter Notebooks. These images, however, also include many other development and modeling tools for data science. If you don't want those extra tools and want a lightweight setup with only Jupyter notebooks, create a custom VM image. For an example, Installing JupyterHub on Azure.

    After you create the custom image, upload the image to a compute gallery to use it with Azure Lab Services. Learn more about using compute gallery in Azure Lab Services.

Lab settings

  1. Create a lab for your lab plan:

    For instructions on how to create a lab, see Tutorial: Set up a lab. Specify the following lab settings:

    Lab settings Value
    Virtual machine size Select Small or Medium for a basic setup accessing Jupyter Notebooks. Select Small GPU (Compute) for compute-intensive and network-intensive applications used in Artificial Intelligence and Deep Learning classes.
    Virtual machine image Choose Data Science Virtual Machine – Windows Server 2019 or Data Science Virtual Machine – Ubuntu depending on your OS needs.
    Template virtual machine settings Select Use virtual machine without customization..
  2. When you create a lab with the Small GPU (Compute) size, follow these steps to install GPU drivers.

    These process installs recent NVIDIA drivers and the Compute Unified Device Architecture (CUDA) toolkit, which you need to enable high-performance computing with the GPU. For more information, see Set up a lab with GPU virtual machines.

Template machine configuration

Once you create a lab, a template VM will be created based on the virtual machine size and image you chose. You configure the template VM with everything you want to provide to your students for this class. For more information, see Create and manage a template in Azure Lab Services.

The Data Science VM images come with many of data science frameworks and tools required for this type of class. For example, the images include:

The Data Science Virtual Machine – Ubuntu image is already provisioned with X2GO server to enable lab users to use a graphical desktop experience.

Enabling tools to use GPUs

If you're using the Small GPU (Compute) size, we recommend that you verify that the Data Science frameworks and libraries are properly set up to use GPUs. You might need to install a different version of the NVIDIA drivers and CUDA toolkit. To configure the GPUs, you should consult the framework's or library's documentation.

For example, to validate that TensorFlow uses the GPU, connect to the template VM and run the following Python-TensorFlow code in Jupyter Notebooks:

import tensorflow as tf
from tensorflow.python.client import device_lib


If the output from the above code looks like the following, TensorFlow isn't using the GPU:

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
incarnation: 15833696144144374634

Continuing with the above example, see TensorFlow GPU Support for guidance. TensorFlow guidance covers:

After you've followed TensorFlow's steps to configure the GPU, when you rerun the test code, you should see output similar to the following output.

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
incarnation: 15833696144144374634
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 11154792128
locality {
  bus_id: 1
  links {
incarnation: 2659412736190423786
physical_device_desc: "device: 0, name: NVIDIA Tesla K80, pci bus id: 0001:00:00.0, compute capability: 3.7"

Provide notebooks for the class

The next task is to provide lab users with notebooks that you want them to use. You can save notebooks locally on the template VM so each lab user has their own copy.

If you want to use sample notebooks from Azure Machine Learning, see how to configure an environment with Jupyter Notebooks.

Publish the template machine

You make the lab VM available for lab users, you have to publish the template. The lab VM has all the local tools and notebooks that you configured previously.

Connect to Jupyter Notebooks

The following sections show different ways for lab users to connect to Jupyter Notebooks on the lab VM.

Use Jupyter Notebooks on the lab VM

Lab users can connect from their local machine to the lab VM and then use Jupyter Notebooks inside the lab VM.

If you use a Windows-based lab VM, lab users can connect to their lab VMs through remote desktop (RDP). For more information, see how to connect to a Windows lab VM.

If you use a Linux-based lab VM, lab users can connect to their lab VMs through SSH or by using X2Go. For more information, see how to connect to a Linux lab VM.

SSH tunnel to Jupyter server on the VM

For Linux-based labs, you can also connect directly from your local computer to the Jupyter server inside the lab VM. The SSH protocol enables port forwarding between the local computer and a remote server (in our case, the user's lab VM). An application that is running on a certain port on the server is tunneled to the mapping port on the local computer.

Follow these steps to configure an SSH tunnel between a user's local machine and the Jupyter server on the lab VM:

  1. Go to the Azure Lab Services website

  2. Verify that the Linux-based lab VM is running.

  3. Select the Connect icon > Connect via SSH to get the SSH connection command.

    The SSH connection command looks like the following:

    ssh -p 12345

    Learn more about how to connect to a Linux VM.

  4. On your local computer, launch a terminal or command prompt, and copy the SSH connection string to it. Then, add -L 8888:localhost:8888 to the command string, which creates the tunnel between the ports.

    The final command should look as follows:

    ssh –L 8888:localhost:8888 -p 12345
  5. Press ENTER to run the command.

  6. When prompted, provide the lab VM password to connect to the lab VM.

  7. When you’re connected to the VM, start the Jupyter server using this command:

    jupyter notebook

    The command outputs a URL for the Jupyter server in the terminal. The URL should look like:

  8. Paste this URL into a browser on your local computer to connect and work on your Jupyter Notebook.


    Visual Studio Code also enables a great Jupyter Notebook editing experience. You can follow the instructions on how to connect to a remote Jupyter server and use the same URL from the previous step to connect from VS Code instead of from the browser.

Cost estimate

This section provides a cost estimate for running this class for 25 lab users. There are 20 hours of scheduled class time. Also, each user gets 10 hours quota for homework or assignments outside scheduled class time. The VM size we chose was small GPU (compute), which is 139 lab units. If you want to use the Small (20 lab units) or Medium size (42 lab units), you can replace the lab unit part in the equation below with the correct number.

Here's an example of a possible cost estimate for this class: 25 lab users * (20 scheduled hours + 10 quota hours) * 139 lab units * 0.01 USD per hour = 1042.5 USD


This cost estimate is for example purposes only. For current details on pricing, see Azure Lab Services Pricing.


In this article, you learned how to create a lab for a Jupyter Notebooks class and how user can connect to their notebooks on the lab VM. You can use a similar setup for other machine learning classes.

Next steps

The template image can now be published to the lab. For more information, see Publish the template VM.

As you set up your lab, see the following articles: