title: How to import your package/modules from a script in bin folder in python
body: <p>When organising python project, this structure seems to be a standard way of doing it:</p>
  
  <pre><code>myproject\
      bin\
          myscript
      mypackage\
          __init__.py
          core.py
      tests\
          __init__.py
          mypackage_tests.py
  setup.py
  </code></pre>
  
  <p>My question is, how do I import my <code>core.py</code> so I can use it in <code>myscript</code>?</p>
  
  <p>both <code>__init__.py</code> files are empty.</p>
  
  <p>Content of <code>myscript</code>:</p>
  
  <pre><code>#!/usr/bin/env python
  from mypackage import core
  if __name__ == '__main__':
      core.main()
  </code></pre>
  
  <p>Content of <code>core.py</code></p>
  
  <pre><code>def main():
      print 'hello'
  </code></pre>
  
  <p>When I run <code>myscript</code> from inside <code>myproject</code> directory, I get the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "bin/myscript", line 2, in &lt;module&gt;
      from mypackage import core
  ImportError: No module named mypackage
  </code></pre>
  
  <p>What am I missing?</p>