# How to make ansible use a certain Python path/executable?

**URL:** <https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880>\
**Category:** Ansible Project\
**Created:** [October 31, 2017, 7:12pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880 "2017-10-31T19:12:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 31, 2017, 7:12pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/1 "2017-10-31T19:12:55Z")

</div>

How do I force Ansible to use a certain version of Python? Is it in the ansible.cfg file? For example, I see via “ansible --version” command that it’s using /usr/local/bin/python v2.6.6, but I want it to use /local/python/bin/python v2.7.x for example?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 31, 2017, 7:19pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/2 "2017-10-31T19:19:05Z")

</div>

Look at ansible\_python\_interpreter: [http://docs.ansible.com/ansible/latest/intro\_inventory.html#list-of-behavioral-inventory-parameters](http://docs.ansible.com/ansible/latest/intro_inventory.html#list-of-behavioral-inventory-parameters)

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [October 31, 2017, 7:58pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/3 "2017-10-31T19:58:49Z")

</div>

Thanks again!

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [November 1, 2017, 3:00pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/4 "2017-11-01T15:00:13Z")

</div>

I set ansible\_python\_interpreter in my ansible.cfg and then in my playbook to point to a Python3.5 installation, but when I still get

`

$ ansible --version  
ansible 2.4.0.0  
config file = /users/myuser/.ansible.cfg  
configured module search path = [u’/users/myuser/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /local/python/lib/python2.7/site-packages/ansible-2.4.0.0-py2.7.egg/ansible  
executable location = /local/python/bin/ansible  
python version = 2.7.14 (default, Oct 10 2017, 13:19:29) [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]

`

---

<div class="post-metadata">

**Author:** ![tkuratom](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tkuratom](https://forum.ansible.com/u/tkuratom)\
**Post date:** [November 1, 2017, 3:27pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/5 "2017-11-01T15:27:40Z")

</div>

It depends on whether you are trying to get ansible to use a different python interpreter for the modules it runs or /usr/bin/ansible on the controller. Matt Martz’s info oncansible\_python\_interpreter is correct for the module side. For the controller side, you would need to change the shebang line of the ansible script. If you are installing ansible you can do that by using something like this to install: /local/python/bin/python setup.py install

When I test and have to use many different python interpreters to test with I often don’t install and instead invoke ansible like this:

/usr/bin/python3.5 $(which ansible) --version

What works best for you will depend on your use case.

---

<div class="post-metadata">

**Author:** ![ZillaYT](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@ZillaYT](https://forum.ansible.com/u/ZillaYT)\
**Post date:** [November 1, 2017, 3:54pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-a-certain-python-path-executable/25880/6 "2017-11-01T15:54:42Z")

</div>

Got it, thanks.
