title: Can anyone explain python's relative imports?
body: <p>I can't for the life of me get python's relative imports to work. I have created a simple example of where it does not function:</p>
  <p>The directory structure is:</p>
  <pre><code>__init__.py
  start.py
  parent.py
  sub/
      __init__.py
      relative.py
  </code></pre>
  <p><code>/start.py</code> contains just: <code>import sub.relative</code></p>
  <p><code>/sub/relative.py</code> contains just <code>from .. import parent</code></p>
  <p>All other files are blank.</p>
  <p>When executing the following on the command line:</p>
  <pre><code>$ cd /
  $ python start.py
  </code></pre>
  <p>I get:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;start.py&quot;, line 1, in &lt;module&gt;
      import sub.relative
    File &quot;/home/cvondrick/sandbox/sub/relative.py&quot;, line 1, in &lt;module&gt;
      from .. import parent
  ValueError: Attempted relative import beyond toplevel package
  </code></pre>
  <p>I am using Python 2.6. Why is this the case? How do I make this sandbox example work?</p>