title: nightmare with relative imports, how does pep 366 work?
body: <p>I have a "canonical file structure" like that (I'm giving sensible names to ease the reading):</p>
  
  <pre><code>mainpack/
  
    __main__.py
    __init__.py 
  
    - helpers/
       __init__.py
       path.py
  
    - network/
       __init__.py
       clientlib.py
       server.py
  
    - gui/
       __init__.py
       mainwindow.py
       controllers.py
  </code></pre>
  
  <p>In this structure, for example modules contained in each package may want to access the <code>helpers</code> utilities through relative imports in something like:</p>
  
  <pre><code># network/clientlib.py
  from ..helpers.path import create_dir
  </code></pre>
  
  <p>The program is runned "as a script" using the <code>__main__.py</code> file  in this way:</p>
  
  <pre><code>python mainpack/
  </code></pre>
  
  <p>Trying to follow the <a href="http://www.python.org/dev/peps/pep-0366/" rel="noreferrer">PEP 366</a> I've put in <code>__main__.py</code> these lines:</p>
  
  <pre><code>___package___ = "mainpack"
  from .network.clientlib import helloclient 
  </code></pre>
  
  <p>But when running:</p>
  
  <pre><code>$ python mainpack 
  Traceback (most recent call last):
    File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main
      "__main__", fname, loader, pkg_name)
    File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
      exec code in run_globals
    File "path/mainpack/__main__.py", line 2, in &lt;module&gt;
      from .network.clientlib import helloclient
  SystemError: Parent module 'mainpack' not loaded, cannot perform relative import
  </code></pre>
  
  <p>What's wrong? What is the correct way to handle and effectively use relative imports?</p>
  
  <p>I've tried also to add the current directory to the PYTHONPATH, nothing changes.</p>