ImportError from third party modules

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

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.

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?

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?