Relative Imports

Scott David Daniels scott.daniels at
Wed Jul 18 03:51:55 CEST 2007

Pat O'Hara wrote:
> Hey guys, I know this is a really stupid question, but I've tried 
> googling and nothing came up. I also tried IRC, but it was too crowded 
> and I didn't get much useful information.
> I'm using Python 2.5 on WinXP, and I'm trying to do a relative import. 
> Here's the package structure
> A/
>   [some more modules]
>   B/
> needs to use; package A's 
> looks like this:
> from aneededmodule import somestuff
> My problem is that when anothermodule tries to import ..aneededmodule or 
> ..somestuff (because somestuff was imported into __init__), I get a 
> ValueError: Attempted relative import in non-package.
> What's my problem? This seems like something very trivial, but I've 
> never had to use python for a project of this size before, so I've never 
> dealt with this.
> Thanks for your help,
> -Pat
My guess (without seeing your code or error messages; shame on you) is
that you are running A/B/; not -m A.B.anothermodule

--Scott David Daniels
scott.daniels at

More information about the Python-list mailing list