# How to install Ansible to run under Python3 on Amazon Linux?

**URL:** <https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [March 12, 2019, 9:36pm UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870 "2019-03-12T21:36:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 12, 2019, 9:36pm UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870/1 "2019-03-12T21:36:36Z")

</div>

There are directions here: [https://docs.ansible.com/ansible/latest/reference\_appendices/python\_3\_support.html](https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html)

Which say:  
The easiest way to run /usr/bin/ansible under Python 3 is to install it with the Python3 version of pip. This will make the default /usr/bin/ansible run with Python3:

$ pip3 install ansible

However this does not work. It will install ansible, but ansible still uses Python2:  
$ ansible --version | grep “python version”  
python version = 2.7.14 (default, Jul 26 2018, 19:59:38) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

the ansible version is 2.7.8  
the aws ami = ami-095cd038eef3e5074 (latest amazon linux base)  
I installed Python3 first, then pip, then Ansible (not sure if the order matters) Does anyone know of a way to get this working? Thanks much for any help

---

<div class="post-metadata">

**Author:** ![Wawrzek\_Niewodniczan](https://avatars.discourse-cdn.com/v4/letter/w/bbe5ce/32.png) [@Wawrzek\_Niewodniczan](https://forum.ansible.com/u/Wawrzek_Niewodniczan)\
**Post date:** [March 13, 2019, 8:04am UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870/2 "2019-03-13T08:04:33Z")

</div>

> There are directions here: [https://docs.ansible.com/ansible/latest/reference\_appendices/python\_3\_support.html](https://docs.ansible.com/ansible/latest/reference_appendices/python_3_support.html)

[...]

> $ pip3 install ansible

[...]

> However this does not work. It will install ansible, but ansible still uses Python2:  
> $ ansible --version | grep "python version"  
> python version = 2.7.14 (default, Jul 26 2018, 19:59:38) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]

[...]

Is it possible that you install ansible with native packing system  
(e.g. yum)? Or maybe it was already installed?

Wawrzek

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 13, 2019, 4:41pm UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870/3 "2019-03-13T16:41:15Z")

</div>

Thank you for the reply - ansible was not already installed and I installed it with pip - here are the commands I used:

sudo yum install python3  
sudo easy\_install pip  
sudo pip3 install ansible

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [March 13, 2019, 6:52pm UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870/4 "2019-03-13T18:52:45Z")

</div>

Yum installing python3 in the first step will automagically pull in the right pip3 (as /usr/bin/pip3, which uses python3).

But then in the second step you issue easy\_install, which overwrites /usr/bin/pip3 with a version that uses python2.  
I think this causes the ansible installation step to also use python2.

So the fix is to simply leave that second step out - on a new instance.  
If you don’t want to instantiate, I think this should get you sorted (not tested):

sudo pip uninstall ansible

sudo pip uninstall pip  
sudo yum remove python3  
sudo yum install python3  
sudo pip3 install ansible

Dick

---

<div class="post-metadata">

**Author:** ![gigit1000](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@gigit1000](https://forum.ansible.com/u/gigit1000)\
**Post date:** [March 13, 2019, 8:43pm UTC](https://forum.ansible.com/t/how-to-install-ansible-to-run-under-python3-on-amazon-linux/29870/5 "2019-03-13T20:43:11Z")

</div>

Thank you – I think the deal was that amazon linux2 comes with several versions of Python3 that you can install and I had to pick a particular one that has pip3. This is just a guess as I don’t know much about how linux distros work. Anyway using these two commands in this order worked for me:

sudo yum -y install python3 python3-pip  
sudo pip3 install ansible
