How to solve the No module named boto3 error in Python?

In today’s tutorial we’ll learn how to troubleshoot import errors related to the Amazon Web Services Python SDK package – boto3.

In Python, we typically see such errors when our program calls 3rd party packages which were not previously imported into your development environment. This happens when using both in Windows, macOS and Linux distributions. Here’s an example from Jupyter Notebook (you’ll get similar error messages in VSCode, PyCharm, Spyder, IDLE and other Python IDEs).

In this tutorial we will learn how to solve this error.

Fix the no module found boto3 error

We typically use the pip (Python package installer) utility to fix import errors. Proceed as following:

  • Save any previously opened Python programs.
  • Close your IDE.
  • Open your Terminal window (in macOS) or your Windows command prompt.
  • Go to the path to your Python environment (location of the python.exe file) in your disk.
  • Go to the scripts folder (replace the path below as applicable)
cd <path_to_your_python_environment>\Scripts

  • Invoke pip as following
pip install boto3
  • Type enter.
  • The boto3 will be collected and installed.
  • Once done close your Terminal or command prompt windows.
  • Launch your IDE and import boto3.

Fixing boto3 module not found error in Anaconda

If you are using Anaconda, you can use the Anaconda command prompt (Windows) or Terminal to fix any import errors you might encounter.

  • Save your open files and exit your IDE.
  • Then open the Anaconda Prompt (Windows only) for macOS and Linux use the terminal
  • Then locate your Anaconda installation by typing
conda info --envs
  • Hit Enter and copy the path to your Anaconda environment.
  • Then activate your required environment and invoke the conda installer:
conda activate <path_conda_environment>
conda install boto3
  • When prompted, confirm the boto3 package installation (by hitting Y), once installation finishes close the Anaconda Prompt.
  • Reopen your IDE and try to import boto3.

Suggested tutorial