Python is a powerful programming language. It is very friendly and easy to learn. During the latest update of this article Python 3.9.4 (of Python 3.9 series) latest stable version is available to download and install.
This tutorial will help you to install Python 3.9 on Amazon Linux systems.
Installing Python from the source code require GCC compiler. So must have installed required development libraries first.
Open a terminal on your system install prerequisites for Python:
sudo yum install gcc openssl-devel bzip2-devel libffi-devel
Step 1 – Download Python 3.9
Visit Python official download page and download the required Python on your system. Alternatively, You can use the following command to download Python 3.9 on local machine.
sudo wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
After download finished, extract the archive file.
sudo tar xzf Python-3.9.4.tgz
Step 2 – Install Python 3.9
Use the below set of commands to compile Python 3.9 from the source code and install using the altinstall command.
sudo ./configure --enable-optimizations
sudo make altinstall
make altinstall is used to prevent replacing the default python binary file /usr/bin/python.
Now remove downloaded source archive file from your system
sudo rm -f /opt/Python-3.9.4.tgz
Step 3 – Check Python Version
The Python 3.9 binary is installed under /usr/local/bin directory. As we have not overwritten the current Python version, you need to run Python 3.9 command as following:
python3.9 -VPython 3.9.4
Step 4 – Create Python Virtual Environment
Python provides to create isolated environment for the application’s. Where you can create a environment directory with specific Python version. This will contains application specific packages.
Use the following command to create environment directory:
python3.9 -m venv env
The above command will create a directory “env” in current directory containing all the required files for isolated environment.
Every time you need to make changes in environment, Use below command to active it.
After activating the environment, you can work with your application.
Once your work finished, use following command to deactivate the Python environment.
In this tutorial, you have learned to install Python 3.9 on Amazon Linux using source code.