Install Python 3.7 on Ubuntu 18.04 LTS

Python is one of the most popular and general-purpose programming languages on demand. It is an interpreted high-level programming language that supports a variety of programming paradigms, including procedural, object-oriented and functional programming. Because of its comprehensive standard library, it is often described as "py comes with a battery".

It is widely used and is a very versatile programming language because it is used by beginners and scientists for different types of activities. It is used for system programming and scripting, repetitive task automation, building websites and web applications, machine learning algorithms, data analysis, etc.

In this tutorial, we will learn how to install Python 3.7 in Ubuntu 18.04 LTS Bionic Beaver. We will include two main ways to install it on an Ubuntu 18.04 machine, one is to use the APT package manager through deadsnake PPA, and the other is to compile from source code.

Use APT (and PPA) to install Python 3.7 on ubuntu

By default, Ubuntu 18.04 comes with Python 3.6.9. You can get the python version by running the following command:

python3 --version
Python 3.6.9

python3-version Python 3.6.9 First, we need to make sure to update the Ubuntu package repository index of the Ubuntu 18.04 computer. This can be done by executing the following command:

$ sudo apt update

After the update is complete, we need to ensure that the "software-properties-common" software package is installed on the computer so that the PPA can be added to the computer.

$ sudo apt install software-properties-common

Now, we can easily add Deadsnakes PPA using the following command:

$ sudo add-apt-repository ppa:deadsnakes/ppa

Finally, after adding the necessary PPA to our Ubuntu 18.04 computer, we can now simply install Python 3.7 using the apt command.

The -y option in the apt notify command can set the automatic yes option as a prompt.

$ sudo apt install python3.7-y
Output
$ sudo apt install python3.7-y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
 libpython3.7-minimal libpython3.7-stdlib python3-distutils python3-lib2to3
 python3.7-minimal
Suggested packages:
 python3.7-venv python3.7-doc binfmt-support
The following NEW packages will be installed:
 libpython3.7-minimal libpython3.7-stdlib python3-distutils python3-lib2to3
 python3.7 python3.7-minimal
0 upgraded,6 newly installed,0 to remove and 321 not upgraded.
Need to get4,792 kB of archives.
After this operation,26.6 MB of additional disk space will be used.
Do you want to continue?[Y/n] y
Get:1 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 libpython3.7-minimal amd64 3.7.7-1+bionic1 [596 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-lib2to3 all 3.6.9-1~18.04[77.4 kB]
Get:3 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.7-minimal amd64 3.7.7-1+bionic1 [1,839 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-distutils all 3.6.9-1~18.04[144 kB]
Get:5 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 libpython3.7-stdlib amd64 3.7.7-1+bionic1 [1,784 kB]
Get:6 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic/main amd64 python3.7 amd64 3.7.7-1+bionic1 [351 kB]
Fetched 4,792 kB in7s(737 kB/s)                                              
Selecting previously unselected package libpython3.7-minimal:amd64.(Reading database ...134446 files and directories currently installed.)
Preparing to unpack .../0-libpython3.7-minimal_3.7.7-1+bionic1_amd64.deb ...
Unpacking libpython3.7-minimal:amd64(3.7.7-1+bionic1)...
Selecting previously unselected package python3.7-minimal.
Preparing to unpack .../1-python3.7-minimal_3.7.7-1+bionic1_amd64.deb ...
Unpacking python3.7-minimal(3.7.7-1+bionic1)...
Selecting previously unselected package libpython3.7-stdlib:amd64.
Preparing to unpack .../2-libpython3.7-stdlib_3.7.7-1+bionic1_amd64.deb ...
Unpacking libpython3.7-stdlib:amd64(3.7.7-1+bionic1)...
Selecting previously unselected package python3-lib2to3.
Preparing to unpack .../3-python3-lib2to3_3.6.9-1~18.04_all.deb ...
Unpacking python3-lib2to3(3.6.9-1~18.04)...
Selecting previously unselected package python3-distutils.
Preparing to unpack .../4-python3-distutils_3.6.9-1~18.04_all.deb ...
Unpacking python3-distutils(3.6.9-1~18.04)...
Selecting previously unselected package python3.7.
Preparing to unpack .../5-python3.7_3.7.7-1+bionic1_amd64.deb ...
Unpacking python3.7(3.7.7-1+bionic1)...
Processing triggers for mime-support(3.60ubuntu1)...
Processing triggers for desktop-file-utils(0.23-1ubuntu3.18.04.2)...
Setting up libpython3.7-minimal:amd64(3.7.7-1+bionic1)...
Setting up python3.7-minimal(3.7.7-1+bionic1)...
Processing triggers for man-db(2.8.3-2ubuntu0.1)...
Processing triggers for gnome-menus(3.13.3-11ubuntu1.1)...
Setting up python3-lib2to3(3.6.9-1~18.04)...
Setting up python3-distutils(3.6.9-1~18.04)...
Setting up libpython3.7-stdlib:amd64(3.7.7-1+bionic1)...
Setting up python3.7(3.7.7-1+bionic1)...

Now, in order to ensure that python is successfully installed, we can check the python version.

$ python3.7-V
Python 3.7.7

Install Python 3.7 on ubuntu from source code

In this method, we will learn how to install Python 3.7 on an Ubuntu 18.04 computer by compiling it from source code. If we want to proceed, we need to ensure that certain prerequisites are met. First, we need to make sure that the build tools needed to compile the source code are installed on our computer.

To do this, we first need to update the local repository index of apt as follows:

$ sudo apt update

With the update of the local repository index, we will now install the dependencies required to compile and install python3.7. To do this, we need to execute the following command:

$ sudo apt install -y build-essential wget zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev

Once all the dependencies are installed and ready, we will use the wget command to download the latest version of Python 3.7 from the official python website as follows:

$ wget https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz
- - 2020- 03- 1716:19:44- - https://www.python.org/ftp/python/3.7.7/Python-3.7.7.tgz
Resolving www.python.org(www.python.org)...151.101.8.223, 2a04:4e42:2::223
Connecting to www.python.org(www.python.org)|151.101.8.223|:443... connected.
HTTP request sent, awaiting response...200 OK
Length:23161893(22M)[application/octet-stream]
Saving to: ‘Python-3.7.7.tgz’

Python-3.7.7.tgz    100%[===================>]22.09M  2.50MB/s    in9.2s

2020- 03- 1716:19:54(2.41 MB/s)- ‘Python-3.7.7.tgz’ saved [23161893/23161893]

In the process of writing this tutorial, the release of python 3.7 was released under the latest version 3.7.7. Therefore, we will only use the tar command to download and extract the tgz file.

$ tar -xf Python-3.7.7.tgz

After extracting the source code from the tgz file, we will now cd into the directory and execute the configure script to evaluate whether the dependencies required for compilation are met. Enable the optimization flag to optimize python binary files and increase code execution by 10-20%.

$ cd Python-3.7.7
$ ./configure --enable-optimizations
checking if the dirent structure of a d_type field... yes
checking for the Linux getrandom() syscall... yes
checking for the getrandom()function... yes
checking for pkg-config... no
checking for openssl/ssl.h in/usr/local/ssl... no
checking for openssl/ssl.h in/usr/lib/ssl... no
checking for openssl/ssl.h in/usr/ssl... no
checking for openssl/ssl.h in/usr/pkg... no
checking for openssl/ssl.h in/usr/local... no
checking for openssl/ssl.h in/usr... yes
checking whether compiling and linking against OpenSSL works... yes
checking for X509_VERIFY_PARAM_set1_host in libssl... yes
checking for--with-ssl-default-suites... python
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Misc/python.pc
config.status: creating Misc/python-config.sh
config.status: creating Modules/ld_so_aix
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile

After successfully executing the configure script, we will now install python 3.7 in the Ubuntu 18.04 LTS computer by using the make command with the altinstall parameter. The altinstall parameter ensures that it is not installed as the default python version of the system.

$ sudo make altinstall
changing mode of/usr/local/bin/idle3.7 to 755
changing mode of/usr/local/bin/pyvenv-3.7 to 755
changing mode of/usr/local/bin/pydoc3.7 to 755
changing mode of/usr/local/bin/2to3-3.7 to 755
rm /usr/local/lib/python3.7/lib-dynload/_sysconfigdata_m_linux_x86_64-linux-gnu.py
rm -r /usr/local/lib/python3.7/lib-dynload/__pycache__
Creating directory /usr/local/share/man/man1
/usr/bin/install -c -m 644./Misc/python.man \
 /usr/local/share/man/man1/python3.7.1if test "xupgrade"!="xno"; then \
 case upgrade in \
 upgrade) ensurepip="--altinstall --upgrade";; \
 install|*) ensurepip="--altinstall";; \
 esac; \
 . /python -E -m ensurepip \
 $ensurepip --root=/; \
fi
Looking in links:/tmp/tmp06ih2lq9
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.2.3 setuptools-41.2.0

Now, we can check whether python 3.7 has been successfully installed by checking its version as follows.

$ python3.7-V
Python 3.7.7

in conclusion

Finally, we have successfully installed python 3.7 on Ubuntu 18.04 LTS computer. At the time of writing this tutorial, the latest version of Python 3.7 is 3.7.7, so you may want to replace version 3.7.7 with the latest version of this release. Now, we can easily execute the python script and code written for 3.7.

Recommended Posts

Install Python 3.7 on Ubuntu 18.04 LTS
Install Python3 on Ubuntu 14.04
Install Python3 on Ubuntu 16.04
Install Python3.7 on Ubuntu
ubuntu18.04 install python2
ubuntu12.04 install python3
ubuntu18.04 install python
How to install Python 3.8 on Ubuntu 18.04
Install Python virtual environment on Ubuntu 18.04
Install TensorFlow (python2.7 version) on Ubuntu
Install the latest Python 3.6 version on Ubuntu
install vscode on ubuntu18
Install Redis on Ubuntu
Install R4 on ubuntu20
Install nvtop on Ubuntu 18.04
Install postgresql-10 on Ubuntu 18.04
Install python3.6 under Ubuntu 16.04
Install docker on Ubuntu
Install Docker on ubuntu18.04
Install nodejs10 on Ubuntu16
Install mysql on Ubuntu 14.04
Install Django on ubuntu
Install Pytorch+CUDA on Ubuntu 16.04
Install rJava on Ubuntu18
Install JDK10+ on Ubuntu
Install python in Ubuntu
How to install Python2 on Ubuntu20.04 ubuntu/focal64
Install KDE on Ubuntu16.04.2
Use python3 to install third on ubuntu
Install Docker on Ubuntu18
Install flashplayer on Ubuntu
[Practice] How to install python3.6 on Ubuntu system
Docker practice (1): install Docker on Ubuntu 16.04
Install ubuntu on virtual machine
Install OpenSSL 1.0.2 on Ubuntu Server 14.04
Install QQ robot on Ubuntu 16.04
Ubuntu install the latest Python 3.
ubuntu18.04 compile and install python3.8
Install Android Studio on Ubuntu
Install python3 on linux, keep python2
Install scrapy framework on ubuntu
Install Mysql offline on Ubuntu
Install Oracle Java8 on Ubuntu
Install Odoo 11 stack on Ubuntu 16.04
Install Go locale on Ubuntu16
Install common software on Ubuntu 16.04
Install non-portable QQ on ubuntu
Install Docker on Ubuntu 18.04 offline
How to install Ruby on Ubuntu 20.04
How to install Memcached on Ubuntu 20.04
How to install Java on Ubuntu 20.04
How to install MySQL on Ubuntu 20.04
How to install VirtualBox on Ubuntu 20.04
How to install Elasticsearch on Ubuntu 20.04
How to install Protobuf 3 on Ubuntu
Install Tenda u12 driver on Ubuntu
How to install Apache on Ubuntu 20.04
How to install Git on Ubuntu 20.04
How to install Node.js on Ubuntu 16.04
How to install MySQL on Ubuntu 20.04
Install and configure MySQL on Ubuntu