# python library path issues

**URL:** <https://forum.ansible.com/t/python-library-path-issues/16497>\
**Category:** Ansible Developer\
**Created:** [October 14, 2014, 1:37am UTC](https://forum.ansible.com/t/python-library-path-issues/16497 "2014-10-14T01:37:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Galbraith](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@Patrick\_Galbraith](https://forum.ansible.com/u/Patrick_Galbraith)\
**Post date:** [October 14, 2014, 1:37am UTC](https://forum.ansible.com/t/python-library-path-issues/16497/1 "2014-10-14T01:37:04Z")

</div>

Hi all,

Simple question–

something I’ve encountered before where python has no problem finding a module but ansible can’t find it:

line 132, in   
from comware\_5\_2 import Comware\_5\_2  
ImportError: No module named comware\_5\_2

But…

Type “help”, “copyright”, “credits” or “license” for more information.

> > > from comware\_5\_2 import Comware\_5\_2

No problem. What am I missing? This is a library a module I wrote uses.

Regards,

Patrick

---

<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 14, 2014, 12:13pm UTC](https://forum.ansible.com/t/python-library-path-issues/16497/2 "2014-10-14T12:13:02Z")

</div>

I’m going to guess that your `which python` is not /usr/bin/python

Ansible by default runs all modules using /usr/bin/python. If your default python is something like /usr/local/bin/python then chances are, that those 2 pythons do not share the same site-packages, and you may have installed that module using /usr/local/bin/python

You can try something like the following to verify:

`which python` -c “import comware\_5\_2; print comware\_5\_2. **file** ”  
/usr/bin/python -c “import comware\_5\_2; print comware\_5\_2. **file** ”

To get ansible to use a different python, you can set ansible\_python\_interpreter. More information is available at \<[http://docs.ansible.com/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine](http://docs.ansible.com/faq.html#how-do-i-handle-python-pathing-not-having-a-python-2-x-in-usr-bin-python-on-a-remote-machine)\>

---

<div class="post-metadata">

**Author:** ![Henry\_Finucane](https://avatars.discourse-cdn.com/v4/letter/h/94ad74/32.png) [@Henry\_Finucane](https://forum.ansible.com/u/Henry_Finucane)\
**Post date:** [October 14, 2014, 2:46pm UTC](https://forum.ansible.com/t/python-library-path-issues/16497/3 "2014-10-14T14:46:48Z")

</div>

If you're using virtualenvs, you should prefer  
#!/usr/bin/env python

to  
#!/usr/bin/python

---

<div class="post-metadata">

**Author:** ![Patrick\_Galbraith](https://avatars.discourse-cdn.com/v4/letter/p/48db29/32.png) [@Patrick\_Galbraith](https://forum.ansible.com/u/Patrick_Galbraith)\
**Post date:** [October 15, 2014, 5:54pm UTC](https://forum.ansible.com/t/python-library-path-issues/16497/4 "2014-10-15T17:54:28Z")

</div>

Thank you both for your replies.

I always do use virtualenv and always do use #!/usr/bin/env python

I think the situation is that I use the virtualenv.

How does one ensure that if they are running ansible in a virtualenv that any host it runs against has the same modules? It creates a temp dir on the host it runs on and that temp dir has everything that is needed, right? How does one make sure that temp dir has everything that is needed?

I solved the issue by installing the module systemically.

Regards,

Patrick

---

<div class="post-metadata">

**Author:** ![Toshio\_Kuratomi](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Toshio\_Kuratomi](https://forum.ansible.com/u/Toshio_Kuratomi)\
**Post date:** [October 20, 2014, 2:24pm UTC](https://forum.ansible.com/t/python-library-path-issues/16497/5 "2014-10-20T14:24:09Z")

</div>

Are you saying that you solved the problem by installing the ComWare  
module onto each machine that you are managing with ansible?

If so, ansible currently does not look at an ansible module's  
dependencies and transfer those to the client. It looks at a few  
special imports to determine if it needs to include code from within  
ansible in the transfer but doesn't have a general facility to handle  
other python modules (Look at ModuleReplacer  
[https://github.com/ansible/ansible/blob/devel/lib/ansible/module\_common.py#L36](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_common.py#L36)  
if you want details).

In the playbook I use to provision new boxes I use the ansible package  
manager modules to install python module packages I know will be  
needed on the client. Other people might install these via the tools  
the OS provides for installing itself or as a first step in a playbook  
that uses the python modules. If a module is not available in your  
package manager, you can use the copy or synchronize modules to copy  
the module over instead.

-Toshio
