[Tutor] Import from project's lib directory?

leam hall leamhall at gmail.com
Thu Aug 28 22:19:44 CEST 2014


On Thu, Aug 28, 2014 at 3:27 PM, Danny Yoo <dyoo at hashcollision.org> wrote:
>>
>> Fails on both Python 2.4 and 2.6 with either ".lib" or "..lib".
>>
>> ### code
>> #!/usr/bin/env python
>>
>> from ..lib import mymodule
>> ####
>>
>> In python/ddl, referencing ../lib/mymodule.py
>>
>>  ./import_test.py
>> Traceback (most recent call last):
>>   File "./import_test.py", line 3, in <module>
>>     from .lib import mymodule
>> ValueError: Attempted relative import in non-package
>
>
> The word "package" has a technical meaning.  Here's a description:
>
>     https://docs.python.org/2/tutorial/modules.html#packages
>
> Can you use packages to structure your code directory?  You'll need
> "__init__.py" files in the directories that are to be treated as
> packages.
>
>
> If you can structure your program into packages, then intra-package
> imports should work:
>
>     https://docs.python.org/2/tutorial/modules.html#intra-package-references

I put empty __init.py__ files in both directories and a few parents.
Still no go.

-- 
Mind on a Mission


More information about the Tutor mailing list