title: import python module using sys.path.append
body: <p>I have two python modules which I am trying to <code>import</code> using <code>sys.path.append</code> and <code>sys.path.insert</code>. Following is my code</p>
  
  <pre><code>import sys
  sys.path.insert(1, "/home/sam/pythonModules/module1")
  sys.path.append("/home/sam/pythonModules/module2")
  
  from lib.module1 import A
  from lib.module2 import B
  </code></pre>
  
  <p>I have following folder structure</p>
  
  <pre><code>/home/sam/pythonModules/module1/lib/module1.py
  /home/sam/pythonModules/module2/lib/module2.py
  </code></pre>
  
  <p>I am able to import lib.module1 but not lib.module2. If I do it like this</p>
  
  <pre><code>import sys
  sys.path.insert(1, "/home/sam/pythonModules/module2")
  sys.path.append("/home/sam/pythonModules/module1")
  
  from lib.module1 import A
  from lib.module2 import B
  </code></pre>
  
  <p>then I am able to <code>import module2</code> but not <code>module1</code>.</p>
  
  <p><em>What can be the reason for the above importing errors?</em></p>
  
  <p>I tried <code>append</code> instead of <code>insert</code> in following manner but it's still doesn't work</p>
  
  <pre><code>import sys
  sys.path.append("/home/sam/pythonModules/module1")
  sys.path.append("/home/sam/pythonModules/module2")
  
  from lib.module1 import A
  from lib.module2 import B
  </code></pre>
  
  <p>Always only first module in <code>sys.path.append</code> is successfully imported.</p>
  
  <p>But I make some changes to paths in <code>sys.path.append</code> in following manner then it works. Both the modules are imported successfully</p>
  
  <pre><code> import sys
   sys.path.append("/home/sam/pythonModules/module1")
   sys.path.append("/home/sam/pythonModules/module2/lib")
  
   from lib.module1 import A
   from module2 import B
  </code></pre>