boto3 python module is installed, but can not be loaded

61 Views Asked by At

python3 and pip3 are installed via homebrew. pip3/pip have boto3 installed, and list this module, but it cannot be imported in python3 in scripts

$ # DEBUG INFO
$
$ which python3 pip3
/opt/homebrew/bin/python3
/opt/homebrew/bin/pip3
$
$ python3 --version ; pip3 --version
Python 3.11.6
pip 24.0 from /opt/homebrew/lib/python3.10/site-packages/pip (python 3.10)
$
$ pip3 install boto3
Requirement already satisfied: boto3 in /opt/homebrew/lib/python3.10/site-packages (1.18.36)
Requirement already satisfied: botocore<1.22.0,>=1.21.36 in /opt/homebrew/lib/python3.10/site-packages (from boto3) (1.21.65)
[...]
$
$ pip3 list | grep boto3
pip3 list | grep boto3
boto3                     1.18.36
$
$ python3
Python 3.11.6 (main, Nov  2 2023, 04:39:43) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
import boto3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'boto3'
>>> quit()
2

There are 2 best solutions below

0
Friendly-Aid On

you are using python3.11 it looks like boto3 is saved in python3.10

pip3 install boto3
Requirement already satisfied: boto3 in /opt/homebrew/lib/`python3.10`/site-packages (1.18.36)
Requirement already satisfied: botocore<1.22.0,>=1.21.36 in /opt/homebrew/lib/`python3.10`/site-packages (from boto3) (1.21.65)

python3
Python `3.11.6` (main, Nov  2 2023, 04:39:43) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

hope this helps!

2
Niusoski On

First of all, start using a virtual environment. Refer this answer https://stackoverflow.com/a/35017813/17184842

Your issue here is that

  1. Python 3.11.6 is installed in /opt/homebrew/bin/python3.
  2. pip 24.0 is installed for Python 3.10 in /opt/homebrew/lib/python3.10/site-packages.

If you want to use boto3 with Python 3.11.6, you need to install it for that specific version of Python. You can do this by running:

/opt/homebrew/bin/python3 -m pip install boto3

This will install boto3 for Python 3.11.6

If you want, you can call python 3.11 explicitly by using:

/opt/homebrew/bin/python3