This error is caused by trying to import boto3
when it’s not installed. Fix this by simply running pip install boto3
.
Table of Contents
Problem: boto3 is not installed
If you don’t have the boto3
Python package installed, running the following code will give you an error:
import boto3
PythonThe error:
Traceback (most recent call last):
File "/home/user/main.py", line 1, in <module>
import boto3
ModuleNotFoundError: No module named 'boto3'
Fix 1: install boto3 using pip
Fix this by simply running the following in your shell:
pip3 install boto3
ShellScriptYou should see the following output:
Defaulting to user installation because normal site-packages is not writeable
Collecting boto3
Downloading boto3-1.26.133-py3-none-any.whl (135 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 135.6/135.6 KB 3.0 MB/s eta 0:00:00
Collecting jmespath<2.0.0,>=0.7.1
Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)
Collecting s3transfer<0.7.0,>=0.6.0
Downloading s3transfer-0.6.1-py3-none-any.whl (79 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 79.8/79.8 KB 7.8 MB/s eta 0:00:00
Collecting botocore<1.30.0,>=1.29.133
Downloading botocore-1.29.133-py3-none-any.whl (10.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.7/10.7 MB 24.3 MB/s eta 0:00:00
Requirement already satisfied: urllib3<1.27,>=1.25.4 in /usr/lib/python3/dist-packages (from botocore<1.30.0,>=1.29.133->boto3) (1.26.5)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/lib/python3/dist-packages (from botocore<1.30.0,>=1.29.133->boto3) (2.8.1)
Installing collected packages: jmespath, botocore, s3transfer, boto3
Successfully installed boto3-1.26.133 botocore-1.29.133 jmespath-1.0.1 s3transfer-0.6.1
Fix 2: install boto3 using PyCharm
First, open PyCharm and click on the “Python Packages” menu item in the bottom left hand corner:
Then, type “boto3” in the search box, and finally click “Install package”.
Conclusion
The error “ModuleNotFoundError: No module named ‘boto3′” is caused by not having the boto3
package installed. Fix it by installing it with pip
or by using the “Python Packages” interface in PyCharm. If you’re using another Python IDE, consult the usage information to find out how to install Python packages in it.
John is a professional software engineer who has been solving problems with code for 15+ years. He has experience with full stack web development, container orchestration, mobile development, DevOps, Windows and Linux kernel development, cybersecurity, and reverse engineering. In his spare time, he’s researching the potential business applications of AI.