ModuleNotFoundError: No module named ‘boto3’ in Python

To integrate our application or Python program with services like AWS, Amazon S3, Amazon DynamoDB, etc. Python provides a “boto3” module. It was maintained and published by AWS. To access this module in Python script, we have to import it at the start of the program. But the “no module named boto3” error arises in the program when the user tries to import the module without being installed in Python.

This post will give you the reason and solutions for the “No module named boto3” error in Python using the following aspects:

So, let’s get started!

Reason: ‘boto3’ Module Not Installed in Python

The prominent reason which causes this error in Python is when a user tries to import the “boto3” module without installing it in Python. The below snippet shows the following error:

The above output shows a “no module named boto3” error because the “boto3” module is not installed in Python.

Solution (For Windows): Install the ‘boto3’ Module in Python

To rectify the error, you need to install the “boto3” module in Python using the pip package manager. You must follow this article to install the “pip” package manager in windows.

Step 1: Open Command Prompt Terminal

After installing Python pip, you can now open the “cmd” terminal again by following the below snippet to install the “boto3” module in Python:

Step 2: Install boto3 Module in Python

To install the “boto3” module in Python you can use the given below pip package manager command in the cmd terminal:

> pip install boto3

The above snippet shows that the “boto3” module was successfully downloaded and installed in Python.

If you get a permission error, you can use the given below command to install Python “boto3” module without any permission:

> install boto3 --user

Step 3: Verification of boto3 Module in Python

After installing the “boto3” module, you can verify the “boto3” module installation using the given below command:

> pip show boto3

The above snippet shows the version, name, and location of the “boto3” module in Python.

We can also check the installed version by using the statement “boto3.__version__” inside the parentheses of print() Function:

Install boto3 Module in Anaconda

To install the “boto3” module in anaconda environment, you can use the given below command:

> conda install -c conda-forge boto3

Install boto3 Module in Jupyter Notebook

To install the “boto3” module in Jupyter Notebook you can use the given below command:

> !pip install boto3

Solution (For Linux): Install ‘boto3’ Module in Python

To install the “boto3” module on Linux you can use the “pip” package manager. To install the “pip” package manager on Linux Ubuntu 22.04, you can follow this specific “Installation Guide”.

After installing Python pip now, you can use the below command to install the “boto3” module in Linux:

$ sudo pip3 install boto3

There is another way that is normally used to install the “boto3” module on Ubuntu 22.04. You can use the given below “apt” commands for installation of the “boto3” module:

Firstly, we update the repositories by using the given below command:

$ sudo apt update

After updating, now we can install the “boto3” module using the following command:

$ sudo apt install boto3

You can also use the given below command to install Python “boto3” module:

$ sudo apt -y install python3-boto3

Alternate Reasons Invoke “ModuleNotFoundError: No module named ‘boto3’”

This error also arises in a program when we installed the package globally in our system but forgot to install it in a virtual environment. Another reason is that we install it correctly, but our Python IDE runs an incorrect version of Python. The solution for all these reasons is the same as discussed earlier (i.e., Install the ‘boto3’ Module in Python).

That’s how the ‘boto3’ module error not found can be fixed.

Conclusion

The “No module named boto3” error occurs in Python when a user tries to import the “boto3” module without installing it in the system. To resolve this error, the user must install the “boto3” module using the “pip” command in Windows and Linux. The “apt” command is also used for installing the “boto3” module in Linux Ubuntu 22.04. This article presented a detailed guide on resolving the “no module named boto3” error in Python.