Sep 18, 2023 4 min read

How to Install Python 3.7 on Ubuntu 20.04

Install Python 3.7 on Ubuntu 20.04 with our step-by-step tutorial. It is one of the most widely used programming languages across the globe.

How to Install Python 3.7 on Ubuntu 20.04
Table of Contents

Choose a different version or distribution


Before we begin talking about how to install Python 3.7 on Ubuntu 20.04, let's briefly understand – What is Python?

Python is one of the most widely used programming languages across the globe. It is an excellent choice for both beginner and skilled developers due to its intuitive and easy-to-learn syntax. Python is a highly flexible programming language. It can be used as a scripting language to design websites, build games, create machine learning algorithms, and analyze data.

Numerous new features have been added to Python 3.7, including support for data classes, context variables, postponed type annotation evaluation, customizable access to module attributes, and more.

The same methods apply to Ubuntu 20.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint, and Elementary OS.

In this tutorial, you will install Python 3.7 on Ubuntu 20.04.

Advantages of Python 3.7

  1. Improved performance: Python 3.7 offers enhanced speed, making applications run faster than previous versions.
  2. Simplified syntax: Syntax optimizations, such as the use of f-strings and async/await keywords, make code easier to write and read.
  3. Data classes: With the introduction of data classes, creating structured data objects becomes more concise and less error-prone.
  4. Built-in breakpoint: A new built-in breakpoint enables interactive debugging, allowing developers to easily inspect and troubleshoot code.
  5. Better handling of typed variables: Python 3.7 supports type hints via the "typing" module, improving code clarity and enabling better tooling for static analysis.


To install packages on your Ubuntu system, you must be logged in as root or a user with sudo access.

Installing Python 3.7 on Ubuntu with Apt

Installing Python 3.7 on Ubuntu with apt is a simple process that will only take a few minutes:

1) Start by installing the prerequisites and updating the package list:

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev

2) After that, add the deadsnakes PPA to your sources list:

sudo add-apt-repository ppa:deadsnakes/ppa

When prompted, click Enter to proceed:


Press [ENTER] to continue or Ctrl-c to cancel adding it.

3) After the repository has been enabled, install Python 3.7 using:

sudo apt install python3.7

4) Python 3.7 is now installed and ready to use on your Ubuntu system. You can check it by typing:

python3.7 --version

Python 3.7.3

Installing Python 3.7 on Ubuntu from Source

We will demonstrate how to download and compile Python 3.7 in this section.

1) First, install the packages required to compile Python source and update the packages list:

sudo apt update
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev wget libbz2-dev

Use the wget command listed below to download the source code of the latest release from the Python download page:


At the time of writing this tutorial, the most recent release is 3.7.4.

3) Unzip the gzipped tarball after the download is finished:

tar -xf Python-3.7.4.tgz

4) Next, head over to the Python source directory and launch the configure script, which will conduct a series of checks to make sure all of your system's dependencies are available:

cd Python-3.7.4
./configure --enable-optimizations

The --enable-optimizations option will optimize the Python binary by running numerous tests. This slows down the building process.

5) Using make, begin the Python build process:

make -j 8

Modify the -j flag in accordance with your processor for a faster build time. If you are unsure about your processor's core count, you can find it by typing nproc. We are using the -j8 flag because the system used for this tutorial has 8 cores.

6) Once the build is complete, use the following command to install the Python binaries:

sudo make altinstall

It is recommended to not use the standard make install, as it will overwrite the default system python3 binary.

7) All done. Python 3.7 has been installed and is ready to use. Type the following command to confirm:

python3.7 --version

The output will display the Python version:


Python 3.7.4

FAQs to Install Python 3.7 on Ubuntu 20.04

Is Python 3.7 available in Ubuntu 20.04's default repositories?

No, Python 3.7 is not available in Ubuntu 20.04's default repositories. However, it can be installed using an alternative method.

What is the deadsnakes repository?

The deadsnakes repository is a PPA created by Felix Krull, which provides different versions of Python that are not available in the official Ubuntu repositories.

What are the terminal commands to install Python 3.7?

After adding the deadsnakes repository, you can install Python 3.7 by running sudo apt install python3.7.

Can I have both Python 3.7 and the default Python version installed?

Yes, it is possible to have multiple Python versions installed on Ubuntu 20.04. Different versions are typically named python3.x, so you can toggle between them as needed.

Will installing Python 3.7 affect my existing Python installations or projects?

Installing Python 3.7 should not affect existing Python installations or projects. However, it's always a good practice to back up your projects or create virtual environments to ensure compatibility and avoid any conflicts.

How can I manage different Python versions using virtual environments?

You can use virtual environment tools like virtualenv or the built-in venv module to create isolated environments for different Python versions. These environments allow you to manage package dependencies and avoid conflicts across projects.

Can I uninstall Python 3.7 if needed?

Yes, you can uninstall Python 3.7 by running sudo apt remove python3.7. However, be cautious and ensure that you are removing the correct version and not affecting other Python installations used by your system or projects.


Hope this detailed guide helped you understand how to install Python 3.7 on your Ubuntu 20.04 system and are ready to start using it to develop your Python 3 project.

Following that, you can read about How to Use PIP and How to Create Python Virtual Environments for various Python projects.

If you have any queries, feel free to drop a comment below, and we'll be happy to help.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.