Why canNOT import from a local directory ?

J

Jia Lu

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 ?
 
T

Thin Myrna

Jia said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top