title: python can't find import module mysteriously
body: <p>I met some python import problems in the past few months. They took me lots of time to locate and now I want to make it clear. </p>
  
  <p>I have a Django project like:</p>
  
  <pre><code>-dir
      -app1
          fun1.py
          util.py
      -util
          http.py
      -app2
          fun2.py
  </code></pre>
  
  <pre><code># fun1.py
  from util.http import http_retry
  </code></pre>
  
  <pre><code># util.py
  def other_funcs():
      pass
  </code></pre>
  
  <pre><code># http.py
  def http_retry:
      pass
  </code></pre>
  
  <p>Situation 1: When I run <code>python app1/fun1.py</code> in <code>dir</code>, I want to import the <code>dir/util/http.py</code>. However, python imported <code>dir/app1/util.py</code>. I have to change the file name of <code>dir/app1/util.py</code> to make it work.</p>
  
  <p>Situation 2: Sometimes I want to run the scripts instead of Django server. But I have to add</p>
  
  <pre><code>import sys
  sys.path.add("/xxx/xxx/dir/")
  </code></pre>
  
  <p>to make it work.</p>
  
  <p>What confuses me more is that both errors just sometime popped mysteriously. Sometimes on my Mac/remote server in Django/script it's ok, after some weeks it's wrong. I searched some blogs about python module. But they are not deep enough to solve my problem.</p>