# Unable to use python 3

**URL:** <https://forum.ansible.com/t/unable-to-use-python-3/38173>\
**Category:** Ansible Project\
**Tags:** rhel, kubernetes\
**Created:** [June 29, 2023, 2:30pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173 "2023-06-29T14:30:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cool\_prat](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@cool\_prat](https://forum.ansible.com/u/cool_prat)\
**Post date:** [June 29, 2023, 2:30pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/1 "2023-06-29T14:30:41Z")

</div>

Hi Team,

I want to use python3 for using k8s module (`kubernetes.core.k8s_info`) on the ansible controller node which RHEL 7.

Python2 is already installed. I have installed python3.

I am trying to use python3 by setting ansible\_python\_interpreter var but its still showing that its using python version 2 in the command like ansible --version.

`ansible_python_interpreter` is already set at multiple level and even after using all the options together, its still not picking up python3 and giving same error.

Have set the var ansible\_python\_interpreter at i) inventory, ii) playbook, iii) /home/sac/ansible.cfg and iv) with -e option as well in ansible-playbook` command.

i) Added in inventory -

# ans.ini #localhost ansible\_connection=local localhost ansible\_python\_interpreter=/opt/rh/rh-python36/root/usr/bin/python3.6

ii) added in playbook

- hosts: localhost connection: local gather\_facts: no vars: ansible\_python\_interpreter: /opt/rh/rh-python36/root/usr/bin/python3.6 tasks: . .

iii) ansible.cfg

# cat ansible.cfg [defaults] ANSIBLE\_PYTHON\_INTERPRETER = /opt/rh/rh-python36/root/usr/bin/python3.6 interpreter\_python = /opt/rh/rh-python36/root/usr/bin/python3.6 ansible\_python\_interpreter = /opt/rh/rh-python36/root/usr/bin/python3.6

iv) Added as -e in ansible-playbook command,

ansible-playbook -i ans.ini ans.yml -e ‘ansible\_python\_interpreter=/opt/rh/rh-python36/root/usr/bin/python3.6’

Below showing python 2.7.5

# ansible --version ansible 2.9.27 config file = /etc/ansible/ansible.cfg configured module search path = [u’/home/sac/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /bin/ansible python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

How can i make changes so that ansible will start using python 3

Thanks,

---

<div class="post-metadata">

**Author:** ![ISHU\_KESHRI\_IT\_116](https://avatars.discourse-cdn.com/v4/letter/i/e0b2c6/32.png) [@ISHU\_KESHRI\_IT\_116](https://forum.ansible.com/u/ISHU_KESHRI_IT_116)\
**Post date:** [June 29, 2023, 2:34pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/2 "2023-06-29T14:34:08Z")

</div>

try to install it through yum pacakge manger

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [June 29, 2023, 10:38pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/3 "2023-06-29T22:38:52Z")

</div>

The Ansible engine side only runs on the python that it was installed in, which in your case is 2.7.5. The ansible\_python\_interpreter controls what Python is used to run the modules on the remote target. You can see what Python was invoked for that scenario by running Ansible with -vvv. If you want to run the Ansible engine with your Python 3.6, the simplest way is to install Ansible with that python version.

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [June 30, 2023, 11:11am UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/4 "2023-06-30T11:11:32Z")

</div>

RHEL 7 published RPMs for a package called "ansible" are from before  
the split, to "ansibl-core" which actually has ansible, and the  
"ansible" package which does not contain ansible, it has a dependency  
on "ansible-core" and installs more than 100 additional modules from  
the ansible galaxy collection. It really should have been called  
"ansible\_collections" .

You're going to hurt yourself if you keep trying to use that. In the  
short term, you can use "pip3 install --user ansible-core" to get a  
much more recent version, ansible-core 2.11. Or bump up to RHEL 8 and  
you can get a contemporary ansible-core via RPM and avoid these  
issues.

---

<div class="post-metadata">

**Author:** ![cool\_prat](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@cool\_prat](https://forum.ansible.com/u/cool_prat)\
**Post date:** [June 30, 2023, 3:29pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/5 "2023-06-30T15:29:48Z")

</div>

Hi @Jbor,

Thanks for your reply.

Even after setting `ansible_python_interpreter` var at different level, i cannot see in the verbose output of playbook command that python3 is getting used on the managed nodes.

Can you please check the playbook output here [https://pastebin.com/zEx6qTXk](https://pastebin.com/zEx6qTXk) if i missing something?

Thanks,

---

<div class="post-metadata">

**Author:** ![cool\_prat](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@cool\_prat](https://forum.ansible.com/u/cool_prat)\
**Post date:** [June 30, 2023, 3:42pm UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/6 "2023-06-30T15:42:48Z")

</div>

Hi @Nico Kadel-Garcia,

Thanks for your detailed reply.

I am trying to understand it. So there is some split and ansible and ansible-core is separated now. I can see in the Redhat Downloads (with whatever subscription i have)  
the latest package for ansible for RHEL7 is `ansible-2.9.27-1.el7ae`. No `ansible-core` i can see for RHEL7. Can see its available for el8, el9.

There is no ansible package for RHEL7 that supports python3?

I have installed python3 on the system but unable to use it for the currently installed ansible (2.9.9).  
Because of this (unable to use python3 on controller node) i am getting issue in using `kubernetes.core.k8s_info` (as its only support python3 and not python2). The error message you can see here - [https://pastebin.com/zEx6qTXk](https://pastebin.com/zEx6qTXk)

Can you please tell me, what if i want to do this via .rpm way and not used pip for this?

Is using pip install the only way to have python3 support for ansible package on controller node on RHEL7 machine?

Thanks,

---

<div class="post-metadata">

**Author:** ![Nico\_Kadel-Garcia](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/nico_kadel-garcia/32/9998_2.png) [@Nico\_Kadel-Garcia](https://forum.ansible.com/u/Nico_Kadel-Garcia)\
**Post date:** [July 4, 2023, 12:45am UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/7 "2023-07-04T00:45:41Z")

</div>

> Hi @Nico Kadel-Garcia,
> 
> Thanks for your detailed reply.
> 
> I am trying to understand it. So there is some split and ansible and ansible-core is separated now. I can see in the Redhat Downloads (with whatever subscription i have)  
> the latest package for ansible for RHEL7 is `ansible-2.9.27-1.el7ae`. No `ansible-core` i can see for RHEL7. Can see its available for el8, el9.
> 
> There is no ansible package for RHEL7 that supports python3?
> 
> I have installed python3 on the system but unable to use it for the currently installed ansible (2.9.9).  
> Because of this (unable to use python3 on controller node) i am getting issue in using `kubernetes.core.k8s_info` (as its only support python3 and not python2). The error message you can see here - [https://pastebin.com/zEx6qTXk](https://pastebin.com/zEx6qTXk)

RHEL 7's copy of "ansible" predates the very peculiar split to  
"ansible-core", which has most of the old code, and a package called  
"ansible" which is dependent on ansible-core, takes up half a Gig of  
space, and consists of more than 100 ansible galaxy collection nodes,  
and doesn't actually contain ansible.

Jump to RHEL 8 to install ansible-core of a current release: or  
install python3 and python3 -pip, and use this:

&nbsp;&nbsp;&nbsp;&nbsp;pip3 install ansible-core --user

i actually publish hooks to build RPMs for recent backports of the  
"ansible-core" and "ansible" packages, but I gave on the obsolete RHEL  
7 python 3 a while ago.

Nico Kadel-Garcia

---

<div class="post-metadata">

**Author:** ![Thanh\_Nguyen\_Duc](https://avatars.discourse-cdn.com/v4/letter/t/c89c15/32.png) [@Thanh\_Nguyen\_Duc](https://forum.ansible.com/u/Thanh_Nguyen_Duc)\
**Post date:** [July 4, 2023, 1:00am UTC](https://forum.ansible.com/t/unable-to-use-python-3/38173/8 "2023-07-04T01:00:49Z")

</div>

I may install python3, create a virtual env and install my ansible-core there then symbol link to the actual os 😂
