What is Python? Python is one of the most used programming languages both by the learners and experienced developers. It is easy to understand and uses a more readable language than any other programming language, making it suitable for beginners and makes it easy to develop web applications. Python has also been used widely as a scripting language, enabling automated processes in Linux systems. In technical terms, python is defined as an object-oriented, high-level programming language with integrated dynamic semantics primarily for web and app development.

Python2 vs Python3

To be able to write Python programs, one is required to have installed Python interpreter in their systems. Python 2 was released in the year 2000, and later version 2.7 in 2010. In 2008, Python3 was released and it started gaining more popularity over python2. Currently, Python 3 is the default Python interpreter.

Ubuntu 20.04 and other versions of Debian Linux ship with Python 3 pre-installed. That being said, Python 2 is legacy while Python3 is the future and most developers are currently writing libraries to be used strictly with Python3. However, some companies still use Python2 for legacy reasons.

How do I install Python2 on Ubuntu 20.04? In this guide, we are going to look at how to install Python2 on Ubuntu 20.04. By default, Ubuntu 20.04 only comes with Python3 pre-installed.

Install Python2 on Ubuntu 20.04

Before any installations, first update and upgrade your system apt. Run the commands below:

sudo apt-get update
sudo apt-get upgrade
sudo reboot

In this guide, we are going to be using PIP (a Python Package Manager) to install various Python packages. We, therefore, need to install pip for Python2. We require Universe repository and get-pip.py script for installing Python 2 PIP tool

sudo add-apt-repository universe
sudo apt update

Now, let’s install python2 on Ubuntu 20.04

sudo apt install python2

Next, we are going to download get-pip.py script for installing Python 2 PIP tool using the below command.

curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py

Install Python 2 pip tool on Ubuntu 20.04

Run the command as shown below to install python2 pip tool

sudo python2 get-pip.py

You should seen an output as below when pip is successfully installed.

Collecting pip 
 Using cached pip-20.2.1-py2.py3-none-any.whl (1.5 MB) 
Installing collected packages: pip 
 Attempting uninstall: pip 
   Found existing installation: pip 20.2.1 
   Uninstalling pip-20.2.1: 
     Successfully uninstalled pip-20.2.1 
Successfully installed pip-20.2.1

You can verify PIP installation by checking on the installed version.

$ pip -V
pip 20.2.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Install Python2 Virtualenv on Ubuntu 20.04

What is Python virtual environment? Virtualenv is a tool for creating Python isolated virtual environments. It enables managing of python projects packages to avoid installing them globally which could tamper with system tools or other projects. To install virtualenv on Ubuntu 20.04, run the below command

sudo apt install virtualenv

Python2 Virtualenv basic usage

Having installed virtualenv, we need to create a directory for virtual environment in our home directory.

$ mkdir ~/.virtualenvs

Change to the virtualenv created directory

$ cd ~/.virtualenvs

In the directory, create a virtual environment for your project. You can do this by specifying the Python interpreter you wish to use.

$ virtualenv --python=python2 env

The command will create a new directory with a name same as the virtual environment. The directory contains all of the isolated files, packages, modules, and executables required by the new environment. You should see an output as below.

created virtual environment CPython2.7.18.candidate.1-64 in 2445ms 
 creator CPython2Posix(dest=/root/env, clear=False, global=False) 
 seeder FromAppData(download=False, progress=latest, wheel=latest, CacheControl=latest, retrying=latest, six=latest, distlib=latest, distro=latest, contextlib2=latest, webencodings=latest, setuptools=latest, appdirs=latest, html5lib=latest, lockfile=latest, msgpack=late
st, ipaddr=latest, pep517=latest, certifi=latest, urllib3=latest, pip=latest, requests=latest, pytoml=latest, chardet=latest, colorama=latest, packaging=latest, pkg_resources=latest, pyparsing=latest, idna=latest, via=copy, app_data_dir=/root/.local/share/virtualenv/seed
-app-data/v1.0.1.debian) 
 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator

To confirm that the environment is installed with the right version of Python interpreter, run the command as shown.

$ ls env/lib
python2.7

To activate the newly created virtual environment, use the command below:

$ source env/bin/activate

You should notice that the name of your virtual environment appears on the left of terminal line and in parentheses.

(env) [email protected]:~/.virtualenvs$

You can go ahead to install your required packages for your project using pip command. As an example, let’s install ‘requests module’. It is a python module that enables sending http requests using python.

$ pip install requests

Once done with working in the virtual environment, you can deactivate it by running the below command:

$ deactivate

Enjoy using Python2 with Virtualenv on Ubuntu 20.04. Remember to check more interesting guides below:

Python Learning books:


<img alt="Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/08/echo/510-dE3N1PL.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming

$39.95

$17.00

 in stock


21 new
from $17.00

17 used from $11.49

Free shipping



as of August 7, 2020 10:18 am


<img alt="Learning Python, 5th Edition" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/08/echo/4109Y1VgveL.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

Learning Python, 5th Edition

$74.99

$47.83

 in stock


17 new
from $43.83

37 used from $30.00

Free shipping



as of August 7, 2020 10:18 am


<img alt="Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud" data-ezsrc="https://computingforgeeks.com/ezoimgfmt/m.media-amazon.com/images/I/51pl3By7R L.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud

$86.65

$76.98

 in stock


9 new
from $76.98

8 used from $73.12

Free shipping



as of August 7, 2020 10:18 am


<img alt="Head First Python: A Brain-Friendly Guide" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/08/echo/513GXqfvg-L.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

Head First Python: A Brain-Friendly Guide

$59.99

$38.95

 in stock


30 new
from $34.95

13 used from $23.53

Free shipping



as of August 7, 2020 10:18 am