ValueError: attempted relative import beyond top-level package
<p>I was playing the the Python's import system in order to understand better how it works, and I encountered another problem. I have the following structure </p>

<pre><code>pkg/
    __init__.py
    c.py
    d.py

    subpkg/
        __init__.py
        a.py
        b.py
</code></pre>

<p>Inside <code>a.py</code> I have the following code:</p>

<pre><code>from . import b
from .. import d
</code></pre>

<p>And inside <code>c.py</code> I have the following:</p>

<pre><code>import subpkg.a
</code></pre>

<p>Now I receive the following error:</p>

<blockquote>
  <p>ValueError: attempted relative import beyond top-level package</p>
</blockquote>

<p>But <strong>why</strong>? How can I solve it? I am running <code>c.py</code> from the IDLE, and <code>pkg</code> should be considered a package, since it has the <code>__init__.py</code> file.</p>

<p>The first import works fine, but it's the following that doesn't work:</p>

<pre><code>from .. import d
</code></pre>

<p>Because I am attempting to import something from a parent package, but apparently I cannot, for some weird reason.</p>