Setting up JupyterLab on Windows 10 with WSL 2

Posted on

Jupyter is a platform for creating interactive “notebooks” which can include text, code and diagrams. It is popular among the scientific community for its ability to manipulate data with Python and display inline graphs from the results. By extension, JupyterLab is, in the project’s own words, “the next-generation web-based user interface for Project Jupyter.”

In this guide, we’ll first install WSL 2 to enable running Ubuntu within Windows 10, and then we’ll install JupyterLab within our Ubuntu distribution.

Setting up WSL 2

Ubuntu on WSL. Install a complete Ubuntu terminal environment in minutes on Windows 10 with Windows Subsystem for Linux (WSL). Access the Linux terminal on Windows, develop cross-platform applications, and manage IT infrastructure without leaving Windows.

We’ll start off by installing Windows Subsystem for Linux – or WSL – version 2. If you’ve done this already, feel free to skip to the next section. This lets us run applications on Ubuntu within a separate, isolated environment to the rest of the Windows 10 installation. Ubuntu is a type of Linux distribution, or in other words, a full operating system that’s based on Linux. It’s also possible to install different distributions in WSL, such as Debian and openSUSE.

Make sure you’re using Windows 10 Build 19041 or higher, or else you won’t be able to use WSL 2. To check this, go to Settings → System → About, and look under Windows specifications. If you’re on an older version, you can update through Windows Update in the Settings app, or using the Windows Update Assistant.

Note: throughout these steps, you may be prompted to install a further update to the WSL kernel. If this occurs, follow the instructions provided before continuing.

First, open PowerShell as an Administrator and run the following commands:

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

The first command enables the Virtual Machine Platform required for WSL, and the second one enables the WSL feature itself. After running these commands, you’ll need to restart your computer to continue.

Now that we’ve restarted the computer, let’s open PowerShell again (this time you don’t need to run as an administrator) and run the following command:

wsl --set-default-version 2

This means that WSL version 2 will be used when we install Ubuntu, rather than the default version 1. To understand how versions 1 and 2 differ, refer to this page from Microsoft highlighting the main differences, but I recommend using version 2 for better performance and compatibility.

Now that we’ve installed and configured WSL, it’s time to install Ubuntu. Click the following link to download Ubuntu from the Microsoft Store, and open the Microsoft Store when prompted. Once it’s installed, press the Launch button. (If you’re familiar with a different Linux distribution, you can install this instead – though I recommend Ubuntu if you’re not sure.)

Ubuntu unpacking in the Windows console

Some further installation will happen, and shortly (usually a minutes or two) you’ll be prompted to set a username and password – both of which can differ from your regular Windows username and password. Once you’ve done that, it’s time to move onto the next step!

Setting up JupyterLab

JupyterLab requires Python 3, as well as a Python package manager – we’ll use pip – so let’s install these now. Open a WSL terminal (if you’re not sure how to do this, search for Ubuntu in the start menu and hit return) and type the following command:

sudo apt install python3 python3-pip

You’ll be prompted for your password that you set earlier - note that it won’t show up on the screen at all as you type, but this is normal. After pressing return, you’ll then be prompted to continue, which you can do by pressing return once again.

Now that you’ve installed Python, it’s time to install JupyterLab:

pip3 install --user jupyterlab pandas matplotlib

Along with JupyterLab, we’ll also install pandas and Matplotlib, as these are two popular Python libraries used in conjunction with Jupyter itself.

We use the --user option to install these packages separately from system packages – system ones are managed by apt (the command we used earlier to install Python) and we could cause problems if we install packages with pip globally, rather than with --user.

Now, run the following command to start running the JupyterLab server:

jupyter lab --no-browser

We specify the --no-browser option to disable automatically opening a browser window, as this feature doesn’t work in WSL, and instead we’ll open the page manually.

The command jupyter lab running in a terminal window, with a URL displayed to open the app

When you want to stop the server, press Control-C in the terminal window. You might be familiar with this keyboard shortcut for copying text, but in a terminal it usually performs the action of “cancelling” (or stopping) the current process. To confirm the shutdown, type y and press return – or press Control-C again.

Assuming you don’t want to stop the server just yet, copy the URL shown in the terminal beginning with http://localhost:8888 and paste it in your usual web browser to get started. A page like the following should appear:

JupyterLab Launcher, showing buttons to create a new notebook or perform other activities

If you’re using Chrome or Edge, you can install the JupyterLab site as an app, as I’ve done in the screenshot above.

And finally, if you’re looking for some projects to try out, have a look at A gallery of interesting Jupyter Notebooks – right now, I’m looking at the Learn Data Science course!

Hopefully you found this guide useful, and if you have any feedback or questions, you can reach out to me on Twitter or use my contact page :)