The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Follow publication

The Founder’s Guide:

How to Install the Jupyter Notebook Server in WSL2

David Littlefield
The Startup
Published in
9 min readNov 9, 2020

--

Image by Vita Vilcina and Lily Banse

The expanded version of this article explains each step with enough detail to learn what’s happening.

Open PowerShell:

  1. Press “⊞ Windows”
  2. Enter “PowerShell” into the search bar
  3. Right-click “Windows PowerShell”
  4. Click “Run as Administrator”

Open WSL2:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
wsl

Install Jupyter Notebook:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
sudo pip install jupyter

Install the WebSocket Extension:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
sudo pip install jupyter_http_over_ws

Create the Configuration File:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
jupyter notebook --generate-config

Open the Jupyter Directory:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
cd $HOME/.jupyter

Create the SSL Certificate:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
  4. Enter “US” into “Country Name”
  5. Press “Enter”
  6. Enter “.” into the remaining fields
  7. Press “Enter”
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

Create the JSON File:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
echo "" > $HOME/.jupyter/jupyter_notebook_config.json

Open the JSON File:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
notepad $HOME/.jupyter/jupyter_notebook_config.json

Edit the JSON File:

  1. Copy the JSON from below these instructions
  2. Paste the JSON into Notepad
  3. Change “Admin” to the Windows username
  4. Change “User” to the Unix username
  5. Click the “File” menu
  6. Click “Save”

Create the Password:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
jupyter notebook password

Open the Firewall Settings:

  1. Press “⊞ Windows”
  2. Enter “Windows Defender Firewall” into the search bar
  3. Click “Windows Defender Firewall”
  4. Click “Advanced Settings” in the left panel

Create an Inbound Rule:

  1. Click “Inbound Rules” in the left panel
  2. Click “New Rule…” in the right panel

Specify the Port:

  1. Select “Port”
  2. Click “Next”
  3. Select “Specific Local Ports”
  4. Enter “8888”
  5. Click “Next”

Allow the Connection:

  1. Select “Allow the Connection”
  2. Click “Next”

Complete the Inbound Rule:

  1. Check “Domain”, “Private” and “Public”
  2. Click “Next”
  3. Copy the name from below these instructions
  4. Paste the name into the “Name” text box
  5. Click “Finish”
Jupyter Notebook Server (WSL2)

Exit WSL2:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
exit

Change the Execution Policy:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
Set-ExecutionPolicy Unrestricted -Force

Open Task Scheduler:

  1. Press “⊞ Windows”
  2. Enter “Task Scheduler” into the search bar
  3. Click “Task Scheduler”

Create the Task:

  1. Click “Create Basic Task” in the right panel
  2. Copy the name from below these instructions
  3. Paste the name into the “Name” text field
  4. Click “Next”
  5. Select “When the Computer Starts”
  6. Click “Next”
  7. Select “Start a Program”
  8. Click “Next”
Jupyter Notebook Server (WSL2)

Specify the Action:

  1. Copy the path from below these instructions
  2. Paste the path into the “Program/Script” text field
  3. Click “Next”
  4. Click “Yes”
  5. Check “Open the Properties Dialog…”
  6. Click “Finish”
Ubuntu 20.04:
powershell.exe -windowstyle hidden -command "bash.exe -c '~/.local/bin/jupyter-notebook --config=~/.jupyter/jupyter_notebook_config.json'"
Ubuntu 18.04: <----------
powershell.exe -windowstyle hidden -command “bash.exe -c ‘/usr/local/bin/jupyter-notebook --config=~/.jupyter/jupyter_notebook_config.json’”

Specify the Trigger:

  1. Click “Triggers” in the top tab bar
  2. Click “At Startup”
  3. Click “Edit”
  4. Check “Delay Task For”
  5. Enter “30 Seconds”
  6. Click “OK”

Run the Task as the User:

  1. Click “General” in the tab bar
  2. Check “Run With Highest Privileges”

Remove the Time Limit:

  1. Click “Settings” in the tab bar
  2. Uncheck “Stop the Task if It Runs Longer Than”
  3. Click “OK”
  4. Restart the computer

Log into the Router:

  1. Open the web browser
  2. Copy the router IP address from below these instructions
  3. Paste the router IP address into the web browser
  4. Press “Enter”
  5. Log into the router

The router IP address varies based on the router manufacturer.

192.168.0.1

Set up Port Forwarding:

  1. Find the “Port Forwarding” page
  2. Paste the IPv4 address into the “Enter IP Address” text field
  3. Copy the port from below these instructions
  4. Paste the port into the “WAN Starting Port” text field
  5. Paste the port into the “WAN Ending Port” text field
  6. Select “All IP Addresses”
  7. Click “Apply”
8888

Get the Network Configuration Information:

  1. Reopen PowerShell
  2. Copy the command from below these instructions
  3. Paste the command into PowerShell
  4. Press “Enter”
  5. Write down the IPv4 Address, Subnet Mask, and Default Gateway.
  6. Write down the DNS Servers.
powershell.exe ipconfig /all

Open the Network Adapter Properties:

  1. Press “⊞ Windows”
  2. Enter “Network Status”
  3. Click “Network Status”
  4. Click “Change Adapter Options”
  5. Right-click the network adapter that’s connected to the internet
  6. Click “Properties”

Set the Static IP Address:

  1. Select “Internet Protocol Version 4 (TCP/IPv4)”
  2. Click “Properties”
  3. Select “Use the Following IP Address”
  4. Enter the TCP/IP information from earlier
  5. Select “Use the Following DNS Server Addresses”
  6. Enter the TCP/IP information from earlier
  7. Click “OK”

Install Net-Tools:

  1. Reopen PowerShell
  2. Copy the command from below these instructions
  3. Paste the command into PowerShell
  4. Press “Enter”

The upcoming PowerShell file uses ifconfig which is included in net-tools.

wsl --exec sudo apt install net-tools

Create the PowerShell File:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
Set-Content jupyter_notebook_port_wsl2.ps1 "" -Encoding ASCII

Open the PowerShell File:

  1. Copy the command from below these instructions
  2. Paste the command into PowerShell
  3. Press “Enter”
notepad jupyter_notebook_port_wsl2.ps1

Edit the PowerShell File:

  1. Copy the script from below these instructions
  2. Paste the script into Notepad
  3. Click the “File” menu
  4. Click “Save”

Open Task Scheduler:

  1. Press “⊞ Windows”
  2. Enter “Task Scheduler” into the search bar
  3. Click “Task Scheduler”

Create the Task:

  1. Click “Create Basic Task” in the right panel
  2. Copy the name from below these instructions
  3. Paste the name into the “Name” text field
  4. Click “Next”
  5. Select “When the Computer Starts”
  6. Click “Next”
  7. Select “Start a Program”
  8. Click “Next”
Jupyter Notebook Port (WSL2)

Specify the Action:

  1. Copy the path from below these instructions
  2. Paste the path into the “Program/Script” text field
  3. Click “Next”
  4. Click “Yes”
  5. Check “Open the Properties Dialog…”
  6. Click “Finish”
powershell.exe -File %userprofile%\.jupyter\jupyter_notebook_port_wsl2.ps1

Specify the Trigger:

  1. Click “Triggers” in the top tab bar
  2. Click “At Startup”
  3. Click “Edit”
  4. Check “Delay Task For”
  5. Enter “30 Seconds”
  6. Click “OK”

Run the Task in the Background:

Click “General” in the tab bar

  1. Select “Run Whether User Is Logged On or Not”
  2. Check “Run With Highest Privileges”

Remove the Time Limit:

  1. Click “Settings” in the tab bar
  2. Uncheck “Stop the Task if It Runs Longer Than”
  3. Click “OK”
  4. Restart the computer

Access the Server From the Local Network:

  1. Log into a different computer or laptop
  2. Connect to the same WiFi network
  3. Enter the IPv4 Address into the web browser
  4. Prepend “https://” to the IP address
  5. Append “8888” to the IP address
  6. Press “Enter”
  7. Type “thisisunsafe”
  8. Enter the password
  9. Click “Log In”

Get the Public IP Address:

  1. Copy the URL from below these instructions
  2. Paste the URL into the web browser
  3. Write down the public IP address
https://www.google.com/search?q=whatsmyip

Access the Server From a Remote Network:

  1. Log into a different computer or laptop
  2. Connect to a different WiFi network
  3. Enter the public IP address into the web browser
  4. Prepend “https://” to the IP address
  5. Append “8888” to the IP address
  6. Press “Enter”
  7. Type “thisisunsafe”
  8. Enter the password
  9. Click “Log In”

Next Steps:

This article is part of a mini-series that helps readers set up everything they need to start using WSL2 for artificial intelligence, machine learning, deep learning, and or data science. It includes articles that contain instructions with copy and paste code and screenshots that help readers get the outcome as soon as possible. It also includes articles that contain instructions with explanations and screenshots that help readers process what’s happening.

01. Install Windows Subsystem for Linux 2 (WSL2)
02. Install the NVIDIA CUDA Driver and Toolkit in WSL2
03. Install Software From Source Code in WSL2
04. Install the Jupyter Notebook Home and Public Server in WSL2
05. Install Virtual Environments in Jupyter Notebook in WSL2
06. Install Programs With a Graphical User Interface in WSL2
07. Install Ubuntu Desktop With a Graphical User Interface in WSL2

Hopefully, this article helped everyone get the prize. If you want to help out then hold the “👋” and click “Follow” to get more content. Thanks for reading!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

David Littlefield
David Littlefield

Written by David Littlefield

From: Non-Technical | To: Technical Founder | Writes: To Make It Easier For Everyone | Topics: #Startups #How-To #Coding #AI #Machine Learning #Deep Learning

No responses yet

Write a response