# How to make Ansible use certain Python libs?

**URL:** <https://forum.ansible.com/t/how-to-make-ansible-use-certain-python-libs/26592>\
**Category:** Ansible Project\
**Tags:** galaxy-ng\
**Created:** [January 29, 2018, 8:41pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-certain-python-libs/26592 "2018-01-29T20:41:32Z")\
**Posts on this page:** 3\
**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:** [January 29, 2018, 8:41pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-certain-python-libs/26592/1 "2018-01-29T20:41:32Z")

</div>

I have

`  
$ which ansible  
/usr/bin/ansible  
user@hostname$ /usr/bin/ansible --version  
ansible 2.4.0.0  
config file = /users/user/.ansible.cfg  
configured module search path = [u’/users/user/.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 = /usr/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)]

`

However, I want Ansible to use

`$ which python2.7 /usr/local/bin/python2.7 user@hostname$ python2.7 -V Python 2.7.14`

I have the following in my ansible.cfg file in my home dir

`ansible_python_interpreter = /usr/local/bin/python2.7`

What’s even more confusing is when I run ansible-galaxy to say create a role, it tries to use python2.6 libs, and I get…

`  
$ ansible-galaxy init test-dict  
Traceback (most recent call last):  
File “/usr/bin/ansible-galaxy”, line 4, in   
**import** (‘pkg\_resources’).run\_script(‘ansible==2.4.0’, ‘ansible-galaxy’)  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 3037, in   
@\_call\_aside  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 3021, in \_call\_aside  
f(\*args, \*\*kwargs)  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 3050, in \_initialize\_master\_working\_set  
working\_set = WorkingSet.\_build\_master()  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 655, in \_build\_master  
ws.require( **requires** )  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 969, in require  
needed = self.resolve(parse\_requirements(requirements))  
File “/usr/lib/python2.6/site-packages/pkg\_resources/ **init**.py”, line 855, in resolve  
raise DistributionNotFound(req, requirers)  
pkg\_resources.DistributionNotFound: The ‘cryptography’ distribution was not found and is required by ansible

`

How can I straighten all this out so Ansible uses the /usr/local/\*/python2.7 paths?

---

<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:** [January 29, 2018, 8:46pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-certain-python-libs/26592/2 "2018-01-29T20:46:18Z")

</div>

You should look at the shebang in /usr/bin/ansible, I’m guessing it doesn’t point to `/usr/local/bin/python2.7`

ansible\_python\_interpreter only affects module execution, not the python interpreter the main ansible process uses.

Likely you should uninstall ansible, and install using that new python. Maybe something like `/usr/local/bin/pip2.7 install ansible`

That is just an assumption, you’ll need to fill in the blanks.

---

<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:** [January 29, 2018, 9:12pm UTC](https://forum.ansible.com/t/how-to-make-ansible-use-certain-python-libs/26592/3 "2018-01-29T21:12:22Z")

</div>

Thanks, that was the issue, the shebang was wrong. I just did a

$ pip install ansible

…which installed 2.4.2.0, and it works now.
