Jupyter Notebook in Windows subsystem for Linux (WSL)

Sayan Ghosh
5 min readMay 11, 2019

--

In this article I will tell you about how you can install Jupyter Notebook which is one of the most popular browser-based interpreter that allows you to interactively work with Python in your Windows Subsystem for Linux.

With the introduction of Windows Subsystem for Linux now users can very easily work on Linux distribution like Ubuntu, Debian, Kali Linux and openSUSE within Windows 10 which is pretty cool and this is actually a real bash shell and not some Virtual Machine or Cygwin. This enhances the Windows experience significantly.

There are a few cons also -

  1. Windows 10 is required.
  2. No GUI (Graphic User Interface). I guess most of the Linux users won’t have any problem with this.
  3. You can’t modify Linux files using the Windows tools but vice-versa is possible.

Installing Windows Subsystem for Linux

I have installed Ubuntu 18.04 LTS on my WSL so the rest of my tutorial will be based on that.

I will now tell you about how you can install WSL on your windows 10.

First go to search and type -

Turn Windows features on or off

After that scroll down to the bottom and you will find the option Windows Subsystem for Linux. You have to tick that to make that feature on and now click OK.

After this you have to restart your system.

Next go to Windows Store and search Linux. You will get something like this-

Result after searching Linux

Now click on Get the apps

As this tutorial is for Ubuntu so I will go for Ubuntu 18.04 LTS.

You install it from here. I have already installed it.

Now Launch Ubuntu and you have to wait till all the necessary additional files get installed. After this you have to enter your UNIX Username and Password. That is all you have to do.

This is what you will get after completing the installation

To check your Ubuntu version type in your bash:

lsb_release -a

Python installation on WSL

Although Python comes preinstalled with most of the Linux distributions but unfortunately it doesn’t comes with WSL. So you have to install it manually and to do that write the following commands —

sudo apt update && upgradesudo apt install python3 python3-pip ipython3

This is it. This will install Python 3 in your WSL. To check python version type

python3 --version

Installing Jupyter Notebook

You can run Jupyter Notebook in your WSL. Here WSL will act as a jupyter server accessible at localhost with port 8888. The steps to install Jupyter is as following-

  1. Install Jupyter by typing the following command in your Bash Shell.
pip3 install jupyter

2. Create alias to launch jupyter without browser from the WSL:

  • Open your bash configuration and type:
nano ~/.bashrc
  • Next you will get something like this where you have to find esac.
  • Now below esac type the following command-
alias jupyter-notebook="~/.local/bin/jupyter-notebook --no-browser"

Next you have to Press Ctrl + X and type Y for Yes and press enter which will take you back to your bash shell.

  • After that you have to source your file by updating your Bash profile by entering:
source ~/.bashrc

Now whenever you will type Jupyter Notebook in your bash you will be directed to the local host. so type:

jupyter notebook

Well you must be suprised now that you have not been directed to the Jupyter server directly?

Don’t worry. Here is the reason.

Well I have written in the cons section that WSL doesn’t have access to GUIs so is it a big problem? Well definitely NO.

After typing jupyter notebook you will get something like this -

All you have to do now is that you have to copy this link and paste it in your favorite browser and you will be directed to the host.

You will get this after pasting the link in your browser.

Now click on New → Python 3

Next your Notebook will open up and you can do your coding here.

Now at the same time you can check your bash shell where things get updated automatically which is obvious.

So this is it. This is the end of the guide. I hope by now you have installed Jupyter Notebook in your Windows Subsystem for Linux without any issues.

Happy coding +_=

May the fourth be with you

--

--