title: How to resolve "ValueError: attempted relative import beyond top-level package"
body: <p>I have the following problem with my project, help me please! Here is the structure of my package:</p>
  
  <pre><code>/pkg
  
  /pkg/__init__.py
  /pkg/sub1/__init__.py
  /pkg/sub2/__init__.py
  
  /pkg/sub1/foo1.py
  /pkg/sub2/foo2.py
  </code></pre>
  
  <p>Here is implementation of foo1.py:</p>
  
  <pre><code>from ..sub2 import foo2
  
  def f():
      print("Hello!")
  </code></pre>
  
  <p>When I run foo1 I get error: <strong>ValueError: attempted relative import beyond top-level package</strong>.</p>
  
  <p>I can solve it doing the following adjustment:</p>
  
  <pre><code>import sys
  import os
  sys.path.append(os.path.abspath(os.path.pardir))
  
  from sub2 import foo2
  def f():
      print("Hello!")
  </code></pre>
  
  <p>But I wonder if there is a way to do it without importing sys and appending parent directory in it.</p>
  
  <p>I heard that if I had .py file '/pkg/start.py' for example which called my foo1 module, then two dots would work. However, is there any way to call foo2 from foo1 directly?</p>