-1

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()
3
  • 1
    python3 --version -> Python 3.11.6. pip3 --version -> pip 24.0 from /opt/homebrew/lib/python3.10 /site-packages/pip (python 3.10) Commented Mar 21, 2024 at 21:28
  • 2
    always use python -m pip install Commented Mar 21, 2024 at 21:34
  • 1
    In addition I would also suggest to always use a virtual environment, i.e. (in your project folder) python3 -m venv .venv then source .venv/bin/activate - now the python and pip commands will be from the virtual env Commented Mar 21, 2024 at 23:16

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Please don't guide this person to creating a Conda environment – virtualenvs and Conda environments are a different thing.
@AKX True, I don't know what I was thinking. Have edited it.
1

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.