Python is known to be a powerful and easy to learn programming language. It is designed to be efficient, simple but with effective approach to object-oriented programming. Python is an ideal language for scripting and rapid application development because of its elegant syntax and dynamic typing, together with its interpreted nature. In this short tutorial I’ll show you how to quickly install Python 3.8 in Amazon Linux 2 server.

Python 3.8 is the newest major release of the Python programming language as of the time when this article is updated. This release contains many new features and optimizations. Among the major new features of Python 3.8 series releases as compared to 3.7 are:

  • PEP 572, Assignment expressions
  • PEP 570, Positional-only arguments
  • PEP 587, Python Initialization Configuration (improved embedding)
  • PEP 590, Vectorcall: a fast calling protocol for CPython
  • PEP 578, Runtime audit hooks
  • PEP 574, Pickle protocol 5 with out-of-band data
  • Typing-related: PEP 591 (Final qualifier), PEP 586 (Literal types), and PEP 589 (TypedDict)
  • Parallel filesystem cache for compiled bytecode
  • Debug builds share ABI as release builds
  • f-strings support a handy = specifier for debugging
  • continue is now legal in finally: blocks
  • on Windows, the default asyncio event loop is now ProactorEventLoop
  • on macOS, the spawn start method is now used by default in multiprocessing
  • multiprocessing can now use shared memory segments to avoid pickling costs between processes
  • typed_ast is merged back to CPython
  • LOAD_GLOBAL is now 40% faster
  • pickle now uses Protocol 4 by default, improving performance

Install Python 3.8 on Amazon Linux 2

The key focus for this article is to help you install Python 3.8 on Amazon Linux 2. There are many standard libraries freely available in source or binary form for all major platforms from the Python Web site, https://www.python.org/ which can be used to extend Python features.

Install from amazon-linux-extras repository

For you to install 3.8 on Amazon Linux 2, you need to have amazon-linux-extras repository installed.

$ which amazon-linux-extras
/usr/bin/amazon-linux-extras

If the command doesn’t return any output, then install the package that will configure the repository:

sudo yum install -y amazon-linux-extras

Confirm if you can see Python 3.8 packages available on the repository.

$ amazon-linux-extras | grep -i python
44  python3.8                available    [ =stable ]

As can be seen from the output python3.8 package is available for installation.

Enable the repository before using it.

sudo amazon-linux-extras enable python3.8

Issue the commands shown below in the terminal to install Python 3.8 on Amazon Linux 2 server.

sudo yum install python3.8

Hit the y key to begin installation of Python 3.8 on Amazon Linux 2 server.

Dependencies Resolved

==================================================================================================================================================================
 Package                                   Arch                         Version                                  Repository                                  Size
==================================================================================================================================================================
Installing:
 python38                                  x86_64                       3.8.2-2.amzn2.0.5                        amzn2extra-python3.8                        69 k
Installing for dependencies:
 python38-libs                             x86_64                       3.8.2-2.amzn2.0.5                        amzn2extra-python3.8                       9.3 M
 python38-pip                              noarch                       9.0.3-2.amzn2.0.1                        amzn2extra-python3.8                       1.9 M
 python38-setuptools                       noarch                       38.4.0-4.amzn2.0.1                       amzn2extra-python3.8                       619 k

Transaction Summary
==================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 12 M
Installed size: 51 M
Is this ok [y/d/N]: y

This is my installation output:

Transaction Summary
==================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 12 M
Installed size: 51 M
Is this ok [y/d/N]: y
Downloading packages:
(1/4): python38-3.8.2-2.amzn2.0.5.x86_64.rpm                                                                                               |  69 kB  00:00:01
(2/4): python38-libs-3.8.2-2.amzn2.0.5.x86_64.rpm                                                                                          | 9.3 MB  00:00:05
(3/4): python38-pip-9.0.3-2.amzn2.0.1.noarch.rpm                                                                                           | 1.9 MB  00:00:04
(4/4): python38-setuptools-38.4.0-4.amzn2.0.1.noarch.rpm                                                                                   | 619 kB  00:00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                             1.6 MB/s |  12 MB  00:00:07
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python38-pip-9.0.3-2.amzn2.0.1.noarch                                                                                                          1/4
  Installing : python38-3.8.2-2.amzn2.0.5.x86_64                                                                                                              2/4
  Installing : python38-setuptools-38.4.0-4.amzn2.0.1.noarch                                                                                                  3/4
  Installing : python38-libs-3.8.2-2.amzn2.0.5.x86_64                                                                                                         4/4
  Verifying  : python38-setuptools-38.4.0-4.amzn2.0.1.noarch                                                                                                  1/4
  Verifying  : python38-3.8.2-2.amzn2.0.5.x86_64                                                                                                              2/4
  Verifying  : python38-pip-9.0.3-2.amzn2.0.1.noarch                                                                                                          3/4
  Verifying  : python38-libs-3.8.2-2.amzn2.0.5.x86_64                                                                                                         4/4

Installed:
  python38.x86_64 0:3.8.2-2.amzn2.0.5

Dependency Installed:
  python38-libs.x86_64 0:3.8.2-2.amzn2.0.5           python38-pip.noarch 0:9.0.3-2.amzn2.0.1           python38-setuptools.noarch 0:38.4.0-4.amzn2.0.1

Complete!

Install from source

If you’re performing this installation at later time when there is a newer release you may find latest version in the extras repository.

For manual installation you need to update system and install dependencies.

sudo yum -y update
sudo yum -y groupinstall "Development Tools"
sudo yum -y install openssl-devel bzip2-devel libffi-devel

Once dependencies are installed, you can then download the latest archive of Python 3.8 release.

sudo yum -y install wget
wget https://www.python.org/ftp/python/3.8.3/Python-3.8.3.tgz

Extract the package.

tar xvf Python-3.8.3.tgz

Change the created directory:

cd Python-3.8*/

Setup installation by running the configure script.

./configure --enable-optimizations

Initiate compilation of Python 3.8 on Amazon Linux 2.

sudo make altinstall

Confirm installed version of Python:

$ python3.8 --version
Python 3.8.3

Setting Default Python version on Amazon Linux 2

The default version of Python available is 2.7 even though we have Python 3.8 installed.

$ python -V
Python 2.7.18

You can interactively call Python 3.8 interpreter with python3.8 command:

$ python3.8 -V
Python 3.8.2

To set Python 3.8 as default version use the update-alternatives command.

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8

Confirm the new setting.

$ sudo update-alternatives --list | grep python
python	auto	/usr/bin/python3.8

Use python command to check current default version.

$ python -V
Python 3.8.2

To reset to Python 2 run the command:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

Python 3.8 has been installed successfully in our Amazon Linux 2 server. For more learning materials on Python refer to the following Learning courses.

(52979)
$18.23
$182.25
in stock
Udemy.com
$15.80
$157.95
in stock
Udemy.com
$15.80
$157.95
in stock
Udemy.com
(16934)
$15.80
$60.74
in stock
Udemy.com

Other articles on Amazon Linux are:

Install PostgreSQL 12 on Amazon Linux 2

Install Docker CE on Amazon Linux 2

Install MariaDB 10.x on Amazon Linux 2

LEAVE A REPLY

Please enter your comment!
Please enter your name here

19 − 4 =