Multiple relative Imports in python 3.5
<p>This structure is just an example</p>

<pre><code>pkg\
  test\
    __init__.py
    test.py
  __init__.py
  source.py
  another_source.py
</code></pre>

<p>another_source.py</p>

<pre><code>class Bar():
  def __init__(self):
    self.name = "bar"
</code></pre>

<p>source.py</p>

<pre><code>from another_source import Bar
class Foo():
  def __init__(self):
    self.name = "foo"
    b = Bar()
</code></pre>

<p>test.py</p>

<pre><code>from ..source import Foo

if __name__== "__main__":
    f = Foo()
    print(f.name)
</code></pre>

<p>Now I want to run test.py. 
As it has been accepted as the <a href="http://stackoverflow.com/questions/11536764/how-to-fix-attempted-relative-import-in-non-package-even-with-init-py">answer</a> I have to go above my current package and run</p>

<pre><code>python -m pkg.test.test
</code></pre>

<p>But this does not work and python gives me a traceback</p>

<pre><code>Traceback (most recent call last):
  File "-\Python35\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "-\Python35\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "~\test\test.py", line 1, in &lt;module&gt;
    from ..source import Foo
  File "~\source.py", line 1, in &lt;module&gt;
    from another_source import Bar
ImportError: No module named 'another_source'
</code></pre>

<p>If I remove all the another_source-stuff it will work, but that is not a solution.</p>

<p>Now is there a sane way to import classes from places that are one directory above me?</p>

<p><code>pkg.source</code> is trying to import things from the <code>pkg.another_source</code> module as if it were top-level. That import needs to be corrected:</p>

<pre><code>from .another_source import Bar
# or
from pkg.another_source import another_source
</code></pre>

python