views:

332

answers:

2

I have a python file "testHTTPAuth.py" which uses module deliciousapi and is kept in "deliciousapi.py".

I have kept the files like

testHTTPAuth.py
lib
   deliciousapi.py

But when i run: "python testHTTPAuth.py" it's giving error

    import deliciousapi
ImportError: No module named deliciousapi

How can handle these python libraries? Because later I have put the code together with libraries as Google app. So I can't keep the library in normal library path.

+1  A: 

If you add an empty __init__.py to your lib directory, you can change your import statement to:

from lib import deliciousapi
Ned Batchelder
it worked but i have more libraries which this 'delicious.py' depended on. For example: this file requires module 'simplejson' can keep the simplejson folder in lib itself?
Saneef
+7  A: 

You need to add the 'lib' directory to your path - otherwise, Python can't find your source. The following (included in a module such as testHTTPAuth.py) will do that:

sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')

Ned's suggestion of changing your imports may work, but if anything in the lib directory imports submodules with absolute paths (most large modules do this), then it'll break.

Nick Johnson