Relative Package Import
Kay Schluehr
kay.schluehr at gmx.net
Wed Jul 9 16:53:26 EDT 2008
On 8 Jul., 21:09, Peter Otten <__pete... at web.de> wrote:
> Robert Hancock wrote:
> > mypackage/
> > __init__.py
> > push/
> > __init__.py
> > dest.py
> > feed/
> > __init__py
> > subject.py
>
> > In subject.py I have
> > from ..push import dest
>
> > But i receive the error:
> > Caught exception importing module subject:
> > File "/usr/local/python/lib/python2.5/site-packages/pychecker/
> > checker.py", line 621, in setupMainCode()
> > module = imp.load_module(self.moduleName, file, filename, smt)
> > File "subject.py", line 1, in <module>()
> > from ..feed import dest
> > ValueError: Attempted relative import in non-package
>
> > What am I missing?
>
> When you run subject as a file
>
> pychecker mypackage/feed/subject.py
>
> subject.py is regarded as a standalone script, not as part of a package. Try
>
> pychecker mypackage.feed.subject
>
> instead to invoke the module via the standard import mechanism.
>
> Peter
Since when are Python modules not regarded as standalone scripts but
as a "part of a package"?
The only indication that there is some duality and that it is relevant
at all are those relative imports that came in with Python 2.5. As it
seems this feature is justified by the artificial semantic differences
it produces.
More information about the Python-list
mailing list