Py3: Import relative path module
__peter__ at web.de
Wed Nov 3 14:42:10 CET 2010
> On Nov 3, 2:51 am, Peter Otten wrote:
>> Slightly generalized: have the importing module print its __name__. There
>> has to be at least one dot in the name for
>> from .. import whatever
>> to succeed.
> Just spent about 3 hours trying every permutation I could think of,
> and searching Google for exactly how to do it, but all I get is:
> ValueError: Attempted relative import in non-package
> How do I import a module so that a dot will appear in its name?
Make sure the no path in sys.path leads into a directory that contains an
__init__.py. In particular, ensure that you aren't invoking the python
interpreter from a working directory that contains an __init__.py and that
the main script is in a directory that doesn't contain an __init__.py.
More information about the Python-list