ImportError from third party modules

85 views
Skip to first unread message

Nitin Kumar

unread,
Jun 9, 2014, 4:53:37 AM6/9/14
to ansible...@googlegroups.com
Hi,

I am using mac. I can notice for different module it takes two path.
either it takes from '/Library/Python/2.7/site-packages or '/System/Library/Frameworks/Python.framework/Versions/2.7/lib

>>> import jinja2

>>> jinja2

<module 'jinja2' from '/Library/Python/2.7/site-packages/jinja2/__init__.pyc'>

>>> import json

>>> json

<module 'json' from '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.pyc'

if i am using any module form /Library/Python/2.7/site-packages in my module being used by playbook i am getting ImportError.


My sample module say just contains 2 lines only (to show you import error):

#!/usr/bin/env python2.7

import jinja2

ansible-playbook playbook.yml -v


PLAY [all] ******************************************************************** 


GATHERING FACTS *************************************************************** 

ok: [jumper]


TASK: [Update apt cache] ****************************************************** 

failed: [jumper] => {"failed": true, "parsed": false}

invalid output was: Traceback (most recent call last):

  File "/var/home/regress/.ansible/tmp/ansible-tmp-1402303699.01-180301714079799/test", line 2, in <module>

    import jinja2

ImportError: No module named jinja2

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 

           to retry, use: --limit @/Users/nitinkr/playbook.retry

jumper                     : ok=1    changed=0    unreachable=0    failed=1  


I am not getting any importError for modules inside /System/Library/Frameworks/Python.framework/Versions/2.7/lib.

One more thing to notice:

from python console $path show to be

>>> import sys

>>> sys.path

['', '/Library/Python/2.7/site-packages/pip-1.5.4-py2.7.egg', '/Library/Python/2.7/site-packages', '/Users/nitinkr/Documents/PyEZ/py-junos-eznc/lib', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC', '/Library/Python/2.7/site-packages']


but same code from module:

#!/usr/bin/env python2.7

import sys

import json

print json.dumps({

    "path" : sys.path

})

show $path as:

ok: [jumper] => {"path": ["/var/home/regress/.ansible/tmp/ansible-tmp-1402303903.41-149497005219721", "/packages/mnt/py-base-i386/usr/lib/python27.zip", "/usr/lib/python2.7", "/usr/lib/python2.7/lib-dynaload", "/usr/lib/python2.7/plat-junos", "/usr/lib/python2.7/site-packages", "/opt/lib/python2.7", "/opt/lib/python2.7/lib-dynaload", "/opt/lib/python2.7/plat-junos", "/opt/lib/python2.7/site-packages", "/packages/mnt/py-base-i386/usr/lib/python2.7/lib-dynload"]}


why is this discrepancies. 

how to resolve my ImportError? I tried adding PATH=$PATH:/Library/Python/2.7/site-packages to ~/.profile but of no use.

Anticipating your reply soon as its blocking my work.

Michael DeHaan

unread,
Jun 9, 2014, 2:57:20 PM6/9/14
to ansible...@googlegroups.com
I do not have these problems on my Mac but it seems like you might have installed a custom Python and have installed some other things with pip from the main python?




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c4aed4a5-5b3f-4889-8be0-bb324df68fc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nitin Kumar

unread,
Jun 10, 2014, 10:40:30 AM6/10/14
to ansible...@googlegroups.com
i didn't install python and was their by default. but yes used pip to install third party modules and these modules gives me ImportError.

one thing to notice, using:
connection: local 
resolves the above problem. what can be the reason?
Reply all
Reply to author
Forward
0 new messages