Version of Python when running Ansible commands

I am using OSX.10.12.6.

I installed ansible via pip3 (in order to use it with Python3 considering Python2 is already installed on my machine by default) and downloaded the ec2.py external inventory script from Ansible github

But when running ansible commands, I get the error:

[WARNING]:  * Failed to parse 
~/ec2.py with script plugin: Inventory script
~/ec2.py) had an execution error: Traceback (most recent call last):   File
"~/ec2.py", line 130, in <module>     import boto ImportError: No module named boto

It seems to be because ansible is using Python2 instead of Python3 (I checked, I cannot import boto or ansible from Python2 but I can from Python3). Also I can run successfully the following python3 ec2.py

What is surprising is that if I run ansible --version, I get the following:

ansible 2.8.3
config file = ~/ansible.cfg
configured module search path = ['/Users/XXXX/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.5 (default, Mar 30 2018, 06:42:10) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

Is there anything I can do to "force" ansible to use Python3 instead of Python2?

PS: Note that I can get through the initial error by pip install boto on Python2, but others error pop up and would rather use Python3

1 answer