Relative imports and package structure in eclipse?
Question: I'm having trouble with relative imports, but I think its because i'm not
understanding package structure completely.

For example, here is my package structure.

    
    
    neo_autorig/                          Source folder, Top level
          __init__.py               
          basic/                  Subpackage for basic utiltites for the script
                  __init__.py
                  name.py
    
          name_test.py
          module_locator.py
    

Theres more than this, but this is basically what i'm using for imports

In name.py i'm importing module locator using

    
    
    from .. import module_locator
    

But it says

    
    
    # Error: line 1: Attempted relative import beyond toplevel package
    

Are top level scripts (like my main script/ui used to execute everything)
supposed to go in the top source folder in the eclipse package? Or am i
setting this up wrong. There are also other sub packages in the source folder,
each with scripts in them.

Edit: If i putanother package in a sub package, I can relative import, its
only the case where i cant relative import from a sub package to a top level
package, and the scripts source is in my python path.


Answer: The python import mechanism works with the `__name__` of the file. Executing a
file directly gives the file the name `"__main__"` instead of its usual name.
The common answer to questions like this would be to run the program with the
-m option. I recommend reading [pep
366](https://www.python.org/dev/peps/pep-0366/) and maybe
[this](http://stackoverflow.com/questions/11536764/attempted-relative-import-
in-non-package-even-with-init-py?rq=1) or
[this](http://stackoverflow.com/questions/1918539/can-anyone-explain-pythons-
relative-imports) question as well.

