How to install boto3 on Amazon Linux 2 – AWS EC2?

Boto3 is an Amazon Web Services (AWS) provided Python software development kit (SDK) for building applications and making them communicate with various AWS services such as Amazon S3, Amazon EC2, Amazon DynamoDB, and more.

It helps developers easily create, configure, and manage AWS services for automating tasks and building more complex applications using AWS infrastructure. It further provides a wide range of features and functionality, including easy-to-use APIs, error handling, pagination, and support for both synchronous and asynchronous operations.

Learn the steps to install Python’s Boto3 library on Amazon Linux 2

1. Run Yum Update

Start with running the system update command before installing anything on your Amazon Linux. For that just use the YUM command given below:

sudo yum update

It will not only install the latest available security update but also rebuild the package manager’s cache.

2. Check Python3 is available

As Boto3 is a Python library, therefore, let’s first check whether Python3 is already installed on our Linux or not. For that you can run the grep command:

yum list installed | grep -i python3

If the above command gives no output, it meant Python3 is not available on your system.

Alternatively, you can also confirm the same by running the command tool of this language:

python3

3. Installing Python 3 & PIP on Amazon Linux

Now, as we are confirmed, python3 is not on our system, so let’s install it using the YUM and the default system repository. Make sure you have sudo or root rights to install the packages.

sudo yum install python3 -y
Installing Python 3 PIP on Amazon Linux

4. Check the Version

After completing the installation, we can confirm the Python3 and PIP 3 versions using:

python3 -V
pip3 -V

To upgrade PIP2 use:

pip3 install pip --upgrade
Check the Version

5. Install Boto3 for Amazon Linux 2

PIP is the package manager for Python and it will get installed automatically as you set up Python 3, so to get the Boto3 we simply need to use PIP3.

pip3 install boto3

However, if you don’t want to install the library globally but instead in an isolated environment just for the application you are developing then create a Python3 environment.

your_app is the directory of the app for which we are creating an environment.

python3 -m venv your_app/env

To activate the created environment for your current bash session, use:

source ~/your_app/env/bin/activate

After that to install the Boto3, use:

pip install pip --upgrade
pip3 install boto3
Install boto3 on Amazon Linux 2

Now, switch to the Python command line and import the Boto3 library to start developing your application.

Once done, if you want to exit the environment then simply type:

deactivate

However, if Boto3 is installed in a Python environment, to use it, every time developers need to source or activate it in bash, manually as we did above. So, those who want their bash to switch automatically to the created environment, need to add its path in their Bashrc file:

echo "source ${HOME}/your_app/env/bin/activate" >> ${HOME}/.bashrc

Replace your_app with your actual app directory name.

To refresh the BashRC file use:

source ~/.bashrc
Can I install boto3 for Python2 on Amazon Linux 2?

Yes, we can install it using the PIP package manager for Python 2, just in your command terminal type – pip install boto3

Can we have both Python 2 and 3 Linux?

Yes, we can have both Python 2 and Python 3 versions on the same Linux system we are using.

Do people still use Python 2?

Lots of projects still rely heavily on Python 2 version, so for them, developers still use Python 2.

How many hours a day do to learn Python?

The more time you devote to learning, the quicker you become a professional Python developer, however, still people recommend giving at least 1 hour a day learning Python.

Other Articles:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.