title: Import a module from a directory (package) one level up
body: <p>What is the right way in Python to import a module from a directory one level up? The directory is a Python package with all these modules and I have a sub directory with code that needs these modules. </p>
  
  <p>The following works just fine, but that is just a hack. I'd like a recommended / pythonic way.</p>
  
  <pre><code>import sys
  sys.path.append("../")
  from fruit import Fruit
  print("OK")
  </code></pre>
  
  <p>The directory structure:</p>
  
  <pre><code>pkg1
     __init__.py  
     fruit.py  
     +sub_pkg
        __init__.py
        recipe.py
  </code></pre>
  
  <p>contents of fruit.py</p>
  
  <pre><code>class Fruit:
     def get_name(self):
         print("Fruit name")
  </code></pre>
  
  <p>contents of <code>sub_pkg/recipe.py</code> .. just a single import line:</p>
  
  <pre><code>from fruit import Fruit
  </code></pre>
  
  <p>When I run : </p>
  
  <pre><code>python recipe.py
  </code></pre>
  
  <p>it gives the following error. </p>
  
  <pre><code>Traceback (most recent call last):
    File "recipe.py", line 2, in &lt;module&gt;
      from fruit import Fruit
  ImportError: No module named fruit
  </code></pre>
  
  <p>I also tried: <code>from pkg1.fruit import Fruit</code> , does not work. Also looked at other similar questions .. 
  <code>python -m recipe.py</code>  or <code>python -m sub_pkg/recipe.py</code> did not work. </p>