boto3/botocore errors with aws_ec2 plugin

Hello, I’m pretty new to ansible. Our group has been using 2.10.17 which has been running fine. I was looking to get the latest version working, but I keep running into an issue with the aws_ec2 plugin. When I check a playbook that references that plugin, I get an error that boto3 or botocore is not installed:

Using inventory plugin 'ansible_collections.amazon.aws.plugins.inventory.aws_ec2' to process inventory source '/Users/jasmartin/Documents/GitHub/SOLENG-smc-ansible-legacy/inventory/production/smc/aws_ec2.yaml'
[WARNING]:  * Failed to parse /Users/jasmartin/Documents/GitHub/SOLENG-smc-ansible-legacy/inventory/production/smc/aws_ec2.yaml with auto plugin: Failed to import the required Python library (botocore and boto3) on
<localhost>'s Python /Users/jasmartin/venv312/bin/python3. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the
wrong Python interpreter, please consult the documentation on ansible_python_interpreter

I’m running ansible in a virtual environment and the libraries are there:

% pip list | grep boto                                                                                                                                  jasmartin@HF7FF70F95
boto3              1.40.24
botocore           1.40.24

I’ve been struggling with this and would appreciate any assistance, thanks!

Is Ansible running under the same user or Python Virtual Environment as you running the pip list command?

Any times I have seen similar issues, it’s because Ansible is running either under a different Python than you think, or a different user (like accidentally using sudo / become: true )

Yes, it’s all running in the same venv:

zsh 1730 % which ansible
/Users/jasmartin/venv312/bin/ansible
zsh 1731 % which pip                                                                                                                                                                                         
/Users/jasmartin/venv312/bin/pip

How did you create the venv? which python did you use?

The check being used is relatively simplistic, it tries importing botocore and boto3, and raises that error if it fails.

Given it’s explicitly mentioning that it’s running using /Users/jasmartin/venv312/bin/python3 I suspect you’ve got the right Python environment being used. It’s possible something’s gone wrong with the module dependencies. Something else to try would be running the python shell and trying to import botocore and boto3:

$ python

import boto3
import botocore

For example:

[10:39:36+0200] ~/vcs/ansible/ansible_collections/amazon/aws  [f619c878c|main|⚑ 6]
[✔ (1s) mchappel@mchappel-thinkpadt14gen3 aws] $ python3.12 
Python 3.12.11 (main, Jun 12 2025, 00:00:00) [GCC 15.1.1 20250521 (Red Hat 15.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'boto3'
>>> 

vs

(ansible-dev311) 
[10:39:51+0200] ~/vcs/ansible/ansible_collections/amazon/aws  [f619c878c|main|⚑ 6]
[✔ (3s) mchappel@mchappel-thinkpadt14gen3 aws] $ python
Python 3.11.13 (main, Jun  4 2025, 00:00:00) [GCC 15.1.1 20250521 (Red Hat 15.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
>>> 

This shouldn’t raise an error, if it does then we’ve got more info on the actual problem. Occasionally I’ve seen modules raise ImportError exceptions for dependencies or bad configuration files.

I’m on MacOS with homebrew installed and have python 3.13.7:

zsh 1533 % which python3                                                                                                                                                                                     jasmartin@HF7FF70F95
/opt/homebrew/bin/python3
zsh 1615 % python3 -V                                                                                                                                                                                        jasmartin@HF7FF70F95
Python 3.13.7

I made the venv with the standard venv creation command:

 python3 -m venv venv312

I do get an error when I try to import boto3:

zsh 1796 % /Users/jasmartin/venv312/bin/python3                                                                                                                                                              jasmartin@HF7FF70F95
Python 3.13.7 (main, Aug 14 2025, 11:12:11) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto3
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import boto3
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/boto3/__init__.py", line 18, in <module>
    from boto3.session import Session
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/session.py", line 26, in <module>
    import botocore.client
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/client.py", line 15, in <module>
    from botocore import (
    ...<3 lines>...
    )
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/waiter.py", line 20, in <module>
    from botocore.docs.docstring import WaiterDocstring
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/docs/__init__.py", line 15, in <module>
    from botocore.docs.service import ServiceDocumenter
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/docs/service.py", line 13, in <module>
    from botocore.docs.bcdoc.restdoc import DocumentStructure
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/docs/bcdoc/restdoc.py", line 17, in <module>
    from botocore.compat import OrderedDict
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/botocore/compat.py", line 31, in <module>
    from dateutil.tz import tzlocal
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/dateutil/tz/__init__.py", line 2, in <module>
    from .tz import *
  File "/Users/jasmartin/venv312/lib/python3.13/site-packages/dateutil/tz/tz.py", line 21, in <module>
    from six.moves import _thread
ModuleNotFoundError: No module named 'six.moves'

Although I have the six library installed:

zsh 1799 [1] % /Users/jasmartin/venv312/bin/pip install six                                                                                                                                              1 ↵ jasmartin@HF7FF70F95
Requirement already satisfied: six in ./venv312/lib/python3.13/site-packages (1.17.0)

This feels familiar, and I think there’s an issue with six…

Pinning the version to six==1.16.0 fixes the issue.

I’m not sure this is something we can really “fix” in the collection, and we’re not hitting it in CI. I’ve a vague memory that it’s tied to both Python 3.12 and six 1.17…

I believe that was it. I switched back to using python 3.9 and I’m not getting the error, thanks!

IIRC you can also bump up to Python 3.13 to clear the error. Ansible Core (including the “ansible” tool itself) is dropping support for older versions of Python on the controllers fairly aggressively.

See also: Releases and maintenance — Ansible Community Documentation

Additionally, Ansible Core < 2.17 is no longer supported by upstream, and the collection isn’t tested on anything older than 2.17. For controllers, Ansible Core 2.17 requires Python 3.10 or later.

Actually I was using 3.13 for the test and was getting six.moves error with it, I had the venv named incorrectly.