title: python package import from different directory
body: <p>I have the following directory structure:</p>
  
  <pre><code>\something\python\
      extras\
          __init__.py # empty file
          decorators.py # contains a benchmark decorator (and other things)
      20131029\   # not a package, this contains the scripts i use directly by doing "python somethingelse.py"
          somethingelse.py
  </code></pre>
  
  <p>And now I want to be able to do something like </p>
  
  <pre><code>from .extras import decorators
  from decorators import benchmark
  </code></pre>
  
  <p>from inside somethingelse.py</p>
  
  <p>For this to work, where do I need to place <code>__init__.py</code> files,  (at the moment, the "\something\python\" path is added to my .tchsrc )</p>
  
  <p>Now, i get the following error:</p>
  
  <pre><code> from .extras import decorators
  ValueError: Attempted relative import in non-package
  </code></pre>
  
  <p>Is this a problem with adding it to my pythonpath? or how should I solve this? The current workaround I have is to just copypaste the decorators.py into each new directory i make (if I make a new version of my code, like the "20131029"), but that is just a stupid workaround which means I have to copypaste a lot of stuff each time i make a new version of my code, so a more elegant version with the correct imports is what I want.</p>
  
  <p>Note: I am working in python 2.7, if that makes any difference?</p>
  
  <p>edit: yes, i run it by doing </p>
  
  <pre><code>python somethingelse.py
  </code></pre>
  
  <p>more edit: no idea if the way that the benchmark decorator is defined matters? (it is not a class or so, the next thing comes exactly out of the decorators.py file) </p>
  
  <pre><code>import time, functools
  def benchmark(func):
      """
      A decorator that prints the time a function takes
      to execute.
      """
      @functools.wraps(func)
      def wrapper(*args, **kwargs):
          t = time.time()
          res = func(*args, **kwargs)
          print func.__name__, time.time()-t
          return res
      return wrapper
  </code></pre>
  
  <p>Edit: if i put the \something\python\extras\ to my pythonpath, i get </p>
  
  <pre><code>ImportError: No module named decorators
  </code></pre>
  
  <p>when i run:</p>
  
  <pre><code>from decorators import benchmark
  </code></pre>
  
  <p>Does this mean that inside that extras-directory i need to make another subdirectory, in which i than put the decorators.py? </p>
  
  <p>edit: in the .tchsrc, i added the following line: </p>
  
  <pre><code>setenv PYTHONPATH /bla/blabla/something/python/extras/
  </code></pre>
  
  <p>and in the somethingelse.py, if i run the following: </p>
  
  <pre><code>import sys
  s = sys.path
  for k in s:
      print k
  </code></pre>
  
  <p>i find that the path /bla/blabla/something/python/extras/ is in that list, so i do not get why it does not work?</p>