Running Jupyter Notebook on WSL while Using Browser on Windows | by Ali Akbar Septiandri | Towards Data Science

If you are a data scientist like me who had just recently moved (back) into Windows, you might find it awkward to get things up and running, especially when you want to have the power of bash terminal at your disposal. You immediately realize that the price you pay for Macs might be really worth it. You get the best of both worlds: GUI-based apps that just work and CLI-based apps to speed up things.
While using Windows subsystem for Linux (WSL) can help me get the good ol’ bash terminal working, it did not give the same ready-to-go experience on running Jupyter Notebook. I also missed the good terminals, like iTerm2 on Mac or Terminator on Ubuntu. You can find people use workarounds like Hyper, or even go back to the old tmux, but I found the former to be sluggish, while the latter is not as easy as iTerm2 or Terminator. In this post, I would like to introduce you to Windows Terminal.
It’s simple, reasonably fast, and iTerm2-like. It’s good.
You can install it from Microsoft Store. You might need to update your Windows first. Don’t worry, it’s worth the wait.
Done?
Disclaimer: I assume that you have already installed WSL with your favorite distro. If you haven’t, follow this guide. In this case, I am using Ubuntu 18.04.
Next, open your Windows Terminal. By default, you should see Windows PowerShell. With Windows Terminal, you can open multiple tabs, switching from Windows PowerShell, Command Prompt, your WSL of choice, and even Azure Cloud Shell. If you want to make bash your default, then hit Ctrl+, or click the down chevron, then click “Settings”.
Find “defaultProfile” and change the value to the “guid” in “profiles” > “defaults” > “list”.
{    "defaultProfile": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",    ...    "profiles":    {        "defaults":        {            ...        },        "list":        [            {                "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",                "hidden": false,                "name": "Ubuntu-18.04",                "source": "Windows.Terminal.Wsl",                "startingDirectory": "//wsl$/Ubuntu-18.04/home/<username>"            },            ...        ]    },    ...}
Notice that I also added the “startingDirectory” to WSL.
With the default settings, you can open a new pane by pressing Alt+Shift+D. Now you don’t need Hyper anymore, do you?
I am assuming that you have installed Python and Jupyter Notebook as well here. If not, I recommend to install them using Anaconda. To remind you, this is to be installed in your WSL.
Next, generate your notebook config by using the following command:
jupyter notebook --generate-config
You will then see a Python file in .jupyter folder. Edit them using your favorite text editor.
code ~/.jupyter/jupyter_notebook_config.py
Disable launching browser by redicect file by changing this line (default value is True):
c.NotebookApp.use_redirect_file = False
The good thing about WSL is that you can open Windows programs directly from bash. Thus, to get your Jupyter Notebook opens up a tab in your browser, you can add them as $BROWSER in bash. I am using Firefox here, but you can swap it with your own favorite browser. In other words, you can edit ~/.bashrc, and add the following line:
export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
Et voila!
The /mnt/c means that you can access your files on Windows directly from bash! Pretty neat isn’t it? So, we are using Firefox on Windows in this case. There’s no need to install Firefox or even X11 on WSL. You can now start your notebook as you have it on Ubuntu or Mac.
Hope you find this useful!