The Founder’s Guide:

How to Install Virtual Environments in Jupyter Notebook on Mac

The expanded tutorial with concise explanations and screenshots

David Littlefield
Mac O’Clock

--

Image by Casey Horner

“The condensed version of this article uses copy and paste code to help you get the outcome ASAP ⚡”

Open Terminal:

The Terminal is an emulator that’s used in Jupyter Notebook to access the file system of the server from the remote computer. It runs on the same computer that’s hosting the server and gives the user with administrative privileges. It also works with most shells and has the same functionalities.

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

Open the Desktop Directory:

The Change Directory (cd) command is used to change the current working directory to the specified directory. It can navigate to absolute and relative paths that start from the root and current working directory, respectively. It can also navigate to paths stored in variables and environment variables.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
cd $HOME/desktop/

Clone the Repository:

The Clone command is used in Git to download the specified repository from GitHub. It copies all the files, subdirectories, branches, and commits for the entire history of the repository. It can also be combined with the recursive flag to copy the submodules the repository uses as dependencies.

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

Open the YoloV3-Tf2 Directory:

The Change Directory (cd) command is used to change the current working directory to the specified directory. It can navigate to absolute and relative paths that start from the root and current working directory, respectively. It can also navigate to paths stored in variables and environment variables.

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

Set the Pyenv Version Environment Variable:

The Environment Variable is a variable that’s automatically created and maintained by the computer. It helps the system know where to install files, find programs, and check for user and system settings. It can also be used by graphical and command-line programs from anywhere on the computer.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
PYENV_VERSION=3.6.8

Create the Virtual Environment:

The Virtual Environment is an isolated Python installation directory that has its own interpreter, site-packages, and scripts. It mostly gets used to prevent version conflicts between dependencies from different projects. It also gets used to meet dependency requirements of different programs from GitHub.

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

Activate the Virtual Environment:

The Activate script is used to start the virtual environment. It prepends the virtual environment path to the PATH environment variable which sets the new Python interpreter and package manager as the default version. It also sets packages to install in the virtual environment installation directory.

  1. Find the Python version from below these instructions
  2. Copy the provided command
  3. Paste the command into Terminal
  4. Press “Return”
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:

The package manager in the virtual environment needs to be upgraded to install the binary packages from the requirements file. This is because the default version is 18.1 but one of the requirements was built according to the Many Linux 2010 specifications which weren’t supported until pip 19.0.

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

Install the Requirements:

The Requirement (r) command is used to install packages that are contained in the specified requirements file. It can install packages whether or not the version number is provided. It can also install packages using files from the computer, over the internet, or specified in a different requirements file.

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

Install Homebrew:

Homebrew is a package manager that provides access to thousands of programs on macOS. It manages the entire installation process which includes downloading, compiling source code, moving files, installing dependencies, creating symbolic links, and deleting installation files.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Wget:

Wget is a program that’s used to retrieve files from the internet using HTTP, HTTPS, and FTP protocols. It can perform recursive downloads, convert links for offline viewing of HTML, and support proxies. It can also perform multiple downloads, resume downloads, and download in the background.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
brew install wget

Download the Weights:

The Weights File is a binary file that contains all of the numerical weight values from a trained model. It can be saved and loaded into a new model that has the same architecture as the original model. This allows the new model to make predictions on new data without needing to be retrained.

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

Convert the Weights:

The weights file can be converted between different frameworks by parsing the model architecture from the configuration file and rebuilding the entire model from scratch. It usually involves rebuilding the layers, rebuilding the model, loading the weights, and saving the weights in the new file format.

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

Use the Repository:

You Only Look Once (YOLOv3) is an open-source object detection algorithm that offers comparable accuracy and faster speeds than other state-of-the-art detection systems during the time of its release. It introduces a handful of incremental improvements which include multi-scale detection, stronger feature detection, bounding box predictions, and multi-label classification.

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

Install the IPython Kernel:

Interactive Python (IPython) is the interactive shell and default kernel that’s used in Jupyter Notebook. It runs the Python code that’s contained in the Jupyter Notebook files. It also adds new functionality such as introspection, parallel computing, rich media, shell syntax, tab completion, and history.

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

Install the Virtual Environment:

The Install command is used in IPython kernel to add the specified virtual environment to the kernels in Jupyter Notebook. It specifies the directory name that’s used to reference the virtual environment. It also specifies the display name that’s used to refer to the virtual environment in file menus.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
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:

The Dashboard in Jupyter Notebook is the user interface that displays the notebooks, files, and subdirectories in the directory where the server was started. It can navigate through the file system and interact with the files. It can also upload files and create new files, subdirectories, and notebooks .

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

Use the Virtual Environment:

The Notebook in Jupyter Notebook is a self-contained document that’s used to represent the visible content in the web application. It includes the inputs and outputs of computations, markdown text, equations, and rich media. It also has its own kernel that runs code with a single programming language.

  1. Refresh the page
  2. Click “New”
  3. Click “yolov3-tf2”

Run the Code Cell:

The Run shortcut is used to execute the code in the selected code cell from the keyboard. It executes the code, selects the next code cell, and displays the output below the code cell. It also displays a number in square brackets to the left of the cell which indicates the order that the code cells were run.

  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”

Run the Code Cell:

The Run shortcut is used to execute the code in the selected code cell from the keyboard. It executes the code, selects the next code cell, and displays the output below the code cell. It also displays a number in square brackets to the left of the cell which indicates the order that the code cells were run.

  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”

Deactivate the Virtual Environment:

The Deactivate command is used to stop the virtual environment. It removes the virtual environment path from the PATH environment variable which sets the last Python interpreter and package manager as the default version. It also sets packages to install in the system Python installation directory.

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

Unset the Pyenv Version Environment Variable:

The Environment Variable is a variable that’s automatically created and maintained by the computer. It helps the system know where to install files, find programs, and check for user and system settings. It can also be used by graphical and command-line programs from anywhere on the computer.

  1. Copy the command from below these instructions
  2. Paste the command into Terminal
  3. Press “Return”
PYENV_VERSION=""

List the Installed Virtual Environments:

The List command is used in IPython kernel to view which virtual environments are currently installed in the list of kernels in Jupyter Notebook. It prints the directory name and location for the virtual environments which use a different path on each operating system.

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

Uninstall the Virtual Environment:

The Uninstall command is used in IPython kernel to delete the specified virtual environment from the kernels in Jupyter Notebook. It specifies the directory name that’s used to find and delete the virtual environment. It also can’t delete the default kernel for Python because it’s a requirement.

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

Hopefully, this article helped you get the 👯‍♀️🏆👯‍♀️, remember to subscribe to get more content 🏅”

Next Steps:

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

Linux:
01. Install and Manage Multiple Python Versions
02. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
03. Install the Jupyter Notebook Server
04. Install Virtual Environments in Jupyter Notebook
05. Install the Python Environment for AI and Machine Learning
WSL2:
01. Install Windows Subsystem for Linux 2
02. Install and Manage Multiple Python Versions
03. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
04. Install the Jupyter Notebook Server
05. Install Virtual Environments in Jupyter Notebook
06. Install the Python Environment for AI and Machine Learning
07. Install Ubuntu Desktop With a Graphical User Interface (Bonus)
Windows 10:
01. Install and Manage Multiple Python Versions
02. Install the NVIDIA CUDA Driver, Toolkit, cuDNN, and TensorRT
03. Install the Jupyter Notebook Server
04. Install Virtual Environments in Jupyter Notebook
05. Install the Python Environment for AI and Machine Learning
Mac:
01. Install and Manage Multiple Python Versions
02. Install the Jupyter Notebook Server
03. Install Virtual Environments in Jupyter Notebook
04. Install the Python Environment for AI and Machine Learning

Glossary:

The Shell is an interpreter that presents the command-line interface to users and allows them to interact with the kernel. It lets them control the system using commands entered from a keyboard. It also translates the commands from the programming language into the machine language for the kernel.
[Return]

The Interpreter is a program that reads through instructions that are written in human readable programming languages and executes the instructions from top to bottom. It translates each instruction to a machine language the hardware can understand, executes it, and proceeds to the next instruction.
[Return]

The Command-Line Interface (CLI) is a program that accepts text input from the user to run commands on the operating system. It lets them configure the system, install software, and access features that aren’t available in the graphical user interface. It also gets referred to as the terminal or console.
[Return]

The Kernel is the program at the heart of the operating system that controls everything in the computer. It facilitates the memory management, process management, disk management, and task management. It also facilitates communication between the programs and hardware in machine language.
[Return]

The Variable is the container that’s used to store different types of values. It can assign or update a value by placing an equals sign between the specified variable name and value without a space around it. It can also reference the stored value by placing a dollar sign in front of the existing variable name.
[Return]

Git is a program that’s used to track changes that are made to the source code over time. It can handle projects of all sizes and allows multiple teams and people to make changes to the same repository. It can also restore the source code to a previous version from the entire history of the repository.
[Return]

The Submodule is a repository that’s nested inside of a different repository as its subdirectory. It contains a copy of all the files for a specific version of the repository at a particular point in time. It also contains a copy of all the submodules within the repository that are considered its dependencies.
[Return]

The Site-Packages is a directory that’s located in the system-wide Python installation directory. It represents the default location that package managers use to install Python packages. It also represents the directory that Python uses to import Python packages that are already installed.
[Return]

The Dependency is an additional binary package that a particular binary package needs to work properly. It can require multiple dependencies to build almost any program that’s distributed by package managers. It also gets downloaded and installed automatically by some package managers.
[Return]

The PATH is an environment variable that contains the list of directories the computer uses to find executable files. It looks for the requested executable file in each directory on the list from top to bottom. It also stops searching once it finds a matching executable file and runs the program or command.
[Return]

The Binary Package is an archive file that contains the files and directories needed to make its containing program work properly. It gets stored in the repository that contains all the programs for a specific Linux distribution. It also requires the Linux package manager to access, extract, and install it.
[Return]

The Source command is used to run commands from the specified script in the current shell. It loads the functions, variables, and configurations from the script into the current shell which become accessible to the user. It also uses any arguments that are provided as positional arguments to the script.
[Return]

The Upgrade (U) option is used in pip to update the specified package that’s already installed on the computer. It can be used to download and install the latest version of the package from the Python Package Index. It can also be used to download and install the latest version of pip package manager.
[Return]

The Requirements File is a text file that’s used in pip to automatically install dependencies that have different version numbers. It specifies each package on a separate line using the package name, double equal sign, and version number. It can also be referenced using a different file name and location.
[Return]

The Weight is a random number that’s multiplied by an input to transform data that’s passed between two nodes in the hidden layers of an artificial neural network. It refers to a learnable parameter that’s used to determine how much influence a feature has on the prediction. It also updates and optimizes during training to increase the accuracy of its future predictions.
[Return]

The Kernel is the program at the heart of the operating system that controls everything in the computer. It facilitates the memory management, process management, disk management, and task management. It also facilitates communication between the programs and hardware in machine language.
[Return]

--

--

David Littlefield
Mac O’Clock

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