By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,676 Members | 2,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,676 IT Pros & Developers. It's quick & easy.

Why canNOT import from a local directory ?

P: n/a
Hi all

I created a folder named *lib* and put a py file *lib.py* in it.
In the upper folder I created a py file as:

<CODE>
import lib.lib

def main():
"""
__doc__
"""
lib.lib.test()
# ////////////////////////////////////////
if __name__ == "__main__":
main()
But I got an error :
#.:python main.py
Traceback (most recent call last):
File "main.py", line 6, in ?
import lib.lib
ImportError: No module named lib.lib

Why ?

May 18 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Jia Lu wrote:
Hi all

I created a folder named *lib* and put a py file *lib.py* in it.
In the upper folder I created a py file as:

<CODE>
import lib.lib

def main():
"""
__doc__
"""
lib.lib.test()
# ////////////////////////////////////////
if __name__ == "__main__":
main()
But I got an error :
#.:python main.py
Traceback (most recent call last):
File "main.py", line 6, in ?
import lib.lib
ImportError: No module named lib.lib

Why ?
You need to define a file __init__.py in your newly created lib directory.

HTH
Thin

May 18 '07 #2

P: n/a
>
You need to define a file __init__.py in your newly created lib directory.
Thank you very much :)
May 18 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.