Why canNOT import from a local directory ?
Thin Myrna
thin.myrna at spamhaters.com
Fri May 18 12:08:05 EDT 2007
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
More information about the Python-list
mailing list