title: How to fix "Attempted relative import in non-package" even with __init__.py
body: <p>I'm trying to follow <a href="http://www.python.org/dev/peps/pep-0328/" rel="noreferrer">PEP 328</a>, with the following directory structure:</p>
  
  <pre><code>pkg/
    __init__.py
    components/
      core.py
      __init__.py
    tests/
      core_test.py
      __init__.py
  </code></pre>
  
  <p>In <code>core_test.py</code> I have the following import statement</p>
  
  <pre><code>from ..components.core import GameLoopEvents
  </code></pre>
  
  <p>However, when I run, I get the following error:</p>
  
  <pre><code>tests$ python core_test.py 
  Traceback (most recent call last):
    File "core_test.py", line 3, in &lt;module&gt;
      from ..components.core import GameLoopEvents
  ValueError: Attempted relative import in non-package
  </code></pre>
  
  <p>Searching around I found "<a href="https://stackoverflow.com/questions/9427037/relative-path-not-working-even-with-init-py">relative path not working even with __init__.py</a>" and "<a href="https://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder/6098238#6098238">Import a module from a relative path</a>" but they didn't help.</p>
  
  <p>Is there anything I'm missing here?</p>