Install jupyter notebook on ubuntu 20.04 using virtualenv
Milind Soorya / August 07, 2021
3 min read
An open-source web application, Jupyter Notebook lets you create and share interactive code, visualisations, and more. It is an essential software used by data scientists. It is often used for working with data, statistical modelling, and machine learning.
If you are using windows the best way to setup Jupyter Notebook is by using Anaconda.
I have an article showing you how to do it here - How to use python virtual environment with Anaconda
if you want to keep the install minimal, and is not likely to use other preinstalled packages from anaconda this article is for you. Using virtualenv package we can create a virtual environment and install the jupyter notebook easily.
By the end of this guide, you will be able to run Python 3 code using Jupyter Notebook running on your system.
In order to complete this guide, you should have a Ubuntu system with non-root user with sudo privileges configured.
Update the local
apt package index and then download and install the packages:
sudo apt update
Next, install pip and the Python header files, which are used by some of Jupyter’s dependencies:
sudo apt install python3-pip python3-dev
Upgrade pip and install the package by typing:
sudo -H pip3 install --upgrade pipsudo -H pip3 install virtualenv
-H flag ensures that the security policy sets the
home environment variable to the home directory of the target user.
virtualenv installed, we can start forming our environment. Create and move into a directory where we can keep our project files.
mkdir ~/ml_projectscd ~/ml_projects
Within the project directory, we’ll create a Python virtual environment.
milindsoorya@predator:~/ml_projects$ virtualenv houseprices_env
it will install a local version of Python and a local version of pip. We can use this to install and configure an isolated Python environment for Jupyter.
Before we install Jupyter, we need to activate the virtual environment. You can do that by typing:
Once the virtual environment is activated, use
pip3, even if you are using Python 3. The virtual environment’s copy of the tool is always named
pip, regardless of the Python version.
(houseprices_env) milindsoorya@predator:~/ml_projects$ pip install jupyter
You now have everything you need to run Jupyter Notebook! To run it, execute the following command:
(houseprices_env) milindsoorya@predator:~/ml_projects$ jupyter notebook
Now the notebook should open automatically in your browser. If it is not opening you can manually copy the URL from the terminal it will usually have a port number of 8888.