Python library path
I 开发者_如何学JAVAhave 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.
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.
If you add an empty __init__.py
to your lib directory, you can change your import statement to:
from lib import deliciousapi
精彩评论