How to do relative imports in Python?
<p>Imagine this directory structure:</p>

<pre><code>app/
   __init__.py
   sub1/
      __init__.py
      mod1.py
   sub2/
      __init__.py
      mod2.py
</code></pre>

<p>I'm coding <code>mod1</code>, and I need to import something from <code>mod2</code>. How should I do it?  </p>

<p>I tried <code>from ..sub2 import mod2</code> but I'm getting an "Attempted relative import in non-package".</p>

<p>I googled around but found only "<code>sys.path</code> manipulation" hacks. Isn't there a clean way?  </p>

<hr>

<p>Edit: all my <code>__init__.py</code>'s are currently empty  </p>

<p>Edit2: I'm trying to do this because sub2 contains classes that are shared across sub packages (<code>sub1</code>, <code>subX</code>, etc.).</p>

<p>Edit3: The behaviour I'm looking for is the same as described in <a href="http://www.python.org/dev/peps/pep-0366/" rel="nofollow">PEP 366</a> (thanks John B)</p>
