Solution:
I opened a Terminal from the top menu (Terminal -> New Terminal);
in the newly opened terminal I typed:
pip install botocore
pip install boto3
After doing this, the errors I was getting for:
import boto3
from botocore.exceptions import ClientError
disappeared (after closing and reopening the Python file I was editing).
Background:
I am new to VisualStudio Code (Version: 1.41.1 on MacOS Mojave 10.14.6) and I was having the same problem.
Import "boto3" could not be resolved/Python, VS Code - Stack Overflow
No module named 'boto3'
"ImportError: No module named boto" when Boto is installed on OS X.
No module named 'boto3' (jupyter) - python3
Videos
Check to ensure vs code is using the correct Python interpreter. You can do this by opening up the command palette (Ctrl+Shift+P), and search "Python: Select Interpreter". Here is a screenshot of what my visual studio code looks like when I go to select the Python interpreter I need at the time.

For more information, here is some useful documentation:
- Getting Started Tutorial for Python in Visual Studio Code
- Using Python Environments in Visual Studio Code
I had the same issue on VS Code.
To solve it, I did these steps:
- Install pip,
sudo apt install python3-pip - Install boto3,
pip install boto3 - Restart VS Code
I'm trying to run the following AWS notebooks inside my conda environment.
The first cell is:
import boto3
import sagemaker
from sagemaker import get_execution_role
ecr_namespace = "sagemaker-training-containers/"
prefix = "script-mode-container"
ecr_repository_name = ecr_namespace + prefix
role = get_execution_role()
account_id = role.split(":")[4]
region = boto3.Session().region_name
sagemaker_session = sagemaker.session.Session()
bucket = sagemaker_session.default_bucket()
print(account_id)
print(region)
print(role)
print(bucket)When I try to run it I get this error - ModuleNotFoundError: No module named 'boto3'
I've pip installed boto3, sagemaker and all relevant dependencies inside my environment and confirmed with $conda list.
I've also checked which environment my interpreter is running and it seems to be the correct one with the required dependencies - Current: ~/anaconda3/envs/local_SageMaker/bin/python.
I had it working fine on windows so I'm confused as to why this isn't working on my linux side.
Does anyone have a solution as to how to get VS Code interpreter to recognise the packages in my conda environment?
There is another possible scenario that might get some people as well (if you have python and python3 on your system):
pip3 install boto3
Note the use of pip3 indicates the use of Python 3's pip installation vs just pip which indicates the use of Python 2's.
Don't use sudo in a virtual environment because it ignores the environment's variables and therefore sudo pip refers to your global pip installation.
So with your environment activated, rerun pip install boto3 but without sudo.
Probably, the best way to deal with multiple python versions is to isolate them using virtualenv
This article covers it's basics and would give you a good overview http://docs.python-guide.org/en/latest/dev/virtualenvs/
If you're using ubuntu, try this out:-
sudo apt install python-boto3
Should work.