Monday, July 25, 2011

Python Module Not Found

Ways to debug when a python code can't find a module:

Open a terminal and start python. Enter:

from imp import *
find_module(module)


See if the path name corresponds with where your module was supposed to be installed or if the path name directs to a __init__.py file


For Example, we were trying to install pyfacebook and our code won't load the module.


find_module(module) was resulting in the following output:
(<open file 'facebook.py', mode 'U' at 0xb752d4f0>, 'facebook.py', ('.py', 'U', 1))


However, the module was installed at (found using a find command):
/usr/lib/python2.7/site-packages/pyfacebook-1.0a2-py2.7.egg


Clearly, when the code was calling from facebook import *, the code was unable to locate __init__.py file and was crashing. To solve the problem, move the files to /usr/lib/python2.7/site-packages/ and see if a further run of find_module points to the required directory.

No comments:

Post a Comment