1

I have installed a python package plivo using the sudo pip install plivo.

and interpreter I test it with some code like:

 >>> import plivo
 >>> p = plivo.RestAPI('xxx', 'yyy')

everything working fine in python interpreter.

Exactly same code is not working in a python script test_plivio.py giving error : AttributeError: 'module' object has no attribute 'RestAPI'

then I checked with dir() in interpreter

>>> dir(plivo)
['Account', 'Application', 'Call', 'Carrier', 'Conference', 'ConferenceMember', 'EndPoint', 'Message', 'Number', 'PLIVO_VERSION', 'PlivoError', 'PlivoResponse', 'Pricing', 'Recording', 'RestAPI', 'SubAccount', 'XML', '__builtins__', '__doc__', '__file__', '__name__', '__package__', 'base64', 'hmac', 'json', 'requests', 'sha1', 'validate_signature']

RestAPI is there.

while in test_plivo.py dir(plivo) is like:

['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'main']

clearly dir(plivo) in script is missing RestAPI with other functions.

Why is that behavior and how to resolve that ?

1
  • Also, if you are using virtualenv, sudo pip install ... will install into your global python, not into your virtualenv. Commented Nov 14, 2013 at 9:55

1 Answer 1

2

You are importing a different module; on your path you have a different plivo.py (or plivo.pyc cached bytecode) file.

Print out the __file__ attribute to see what is imported instead:

print plivo.__file__

and rename that or move it somewhere else.

Sign up to request clarification or add additional context in comments.

2 Comments

i made a mistake to keep the name of script as plivo.py. Although i remaned it test_plivo.py there was a plivo.pyc and my import was importing that file. thanks
@naveenyadav: Indeed, a cached bytecode file would also mask another module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.