DEV Community

milindsoorya
milindsoorya

Posted on • Edited on • Originally published at milindsoorya.co.uk

2 2

How To Set Up Jupyter Notebook with Python 3 on Ubuntu 20.04

Introduction

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.

By the end of this guide, you will be able to run Python 3 code using Jupyter Notebook running on your system.

Prerequisites

In order to complete this guide, you should have a Ubuntu system with non-root user with sudo privileges configured.

Step 1 — Set Up Python

update the local apt package index and then download and install the packages:

sudo apt update
Enter fullscreen mode Exit fullscreen mode

Next, install pip and the Python header files, which are used by some of Jupyter’s dependencies:

sudo apt install python3-pip python3-dev
Enter fullscreen mode Exit fullscreen mode

Step 2 — Create a Python Virtual Environment for Jupyter

Upgrade pip and install the package by typing:

sudo -H pip3 install --upgrade pip
sudo -H pip3 install virtualenv
Enter fullscreen mode Exit fullscreen mode

The -H flag ensures that the security policy sets the home environment variable to the home directory of the target user.

With virtualenv installed, we can start forming our environment. Create and move into a directory where we can keep our project files.

mkdir ~/ml_projects
cd ~/ml_projects
Enter fullscreen mode Exit fullscreen mode

Within the project directory, we’ll create a Python virtual environment.

user@pc:~/ml_projects$ virtualenv houseprices_env
Enter fullscreen mode Exit fullscreen mode

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:

source houseprices_env/bin/activate
Enter fullscreen mode Exit fullscreen mode

Step 3 — Install Jupyter

Once the virtual environment is activated, use pip instead of 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) user@pc:~/ml_projects$ pip install jupyter
Enter fullscreen mode Exit fullscreen mode

Step 4 — Run Jupyter Notebook

You now have everything you need to run Jupyter Notebook! To run it, execute the following command:

(houseprices_env) user@pc:~/ml_projects$ jupyter notebook
Enter fullscreen mode Exit fullscreen mode

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay