The Founder’s Guide:

How to Install Virtual Environments in Jupyter Notebook in WSL2

The condensed tutorial with instructions and screenshots

David Littlefield
6 min readNov 10, 2020
Image by Casey Horner

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

Open Terminal:

  1. Open the web browser
  2. Enter the IP address to the Jupyter Notebook server
  3. Press “Enter”
  4. Click “New”
  5. Click “Terminal”

Set the Username Variable:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
username=$(wslvar USERNAME)

Open the Desktop Directory:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
cd /mnt/c/users/$username/desktop/

Clone the Repository:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
git clone --recursive https://github.com/zzh8829/yolov3-tf2.git

Open the YoloV3-Tf2 Directory:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
cd yolov3-tf2

Create the Virtual Environment:

  1. Find the Python version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Enter”
Python 3.5:
python3.5 -m venv venv35
Python 3.6: <----------
python3.6 -m venv venv36
Python 3.7:
python3.7 -m venv venv37
Python 3.8:
python3.8 -m venv venv38

Activate the Virtual Environment:

  1. Find the Python version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Enter”
Python 3.5:
source venv35/bin/activate
Python 3.6: <----------
source venv36/bin/activate
Python 3.7:
source venv37/bin/activate
Python 3.8:
source venv38/bin/activate

Upgrade Pip:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
pip install --upgrade pip

Open the Requirements File:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
vim requirements.txt

Delete the Requirements:

  1. Type “:%d” to delete the text
  2. Press “Enter”

Install the Requirements:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
pip install --requirement requirements.txt

Download the Weights:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
wget https://pjreddie.com/media/files/yolov3.weights -O data/yolov3.weights

Convert the Weights:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
python convert.py --weights ./data/yolov3.weights --output ./checkpoints/yolov3.tf

Use the Virtual Environment:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
python detect.py --image ./data/meme.jpg

Install IPython Kernel:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
pip install ipykernel

Deactivate the Virtual Environment:

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

Install the Virtual Environment:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
Python 3.5:
sudo venv35/bin/python -m ipykernel install --name yolov3-tf2 --display-name "yolov3-tf2"
Python 3.6: <----------
sudo venv36/bin/python -m ipykernel install --name yolov3-tf2 --display-name "yolov3-tf2"
Python 3.7:
sudo venv37/bin/python -m ipykernel install --name yolov3-tf2 --display-name "yolov3-tf2"
Python 3.8:
sudo venv38/bin/python -m ipykernel install --name yolov3-tf2 --display-name "yolov3-tf2"

Open the YoloV3-Tf2 Directory:

  1. Reopen Jupyter Notebook
  2. Click the “Desktop” folder
  3. Click the “YoloV3-Tf2” folder

Use the Virtual Environment:

  1. Click “New”
  2. Click “yolov3-tf2”

Initialize the Detector:

  1. Copy the code from below these instructions
  2. Click an empty cell in Jupyter Notebook
  3. Paste the code into the empty cell
  4. Press “Shift” + “Enter”

Detect the Image:

  1. Copy the code from below these instructions
  2. Click an empty cell in Jupyter Notebook
  3. Paste the code into the empty cell
  4. Press “Shift” + “Enter”

List the Installed Virtual Environments:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
jupyter kernelspec list

Remove the Virtual Environment:

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Enter”
sudo jupyter kernelspec uninstall yolov3-tf2

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!

--

--

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