title: Module import precedence in Pyinstaller program
body: <p>I am trying to have an easy way to update a program I am working on, by being able to just place replacement .py files in a folder which I then put at the top of the sys.path list so all import statements will first check that folder and not my top level directory, importing the newer .py files and not the ones used to build the program originally with PyInstaller.  Right now, if I use this code:</p>
  
  <pre><code>    import sys,os
      bundlePath = 'c:/tests/importTest' 
      print ("Bundle path: {}".format(bundlePath))
      importPath = bundlePath + '/uploads'
      sys.path.insert(0,importPath)
      print ("Import path: {}".format(sys.path[0]))
      os.chdir(sys.path[0])
      import testyTastery
      print(testyTastery.message)
  </code></pre>
  
  <p>My Python IDE or running this script through the command line will print the message from <code>uploads/testyTastery.py</code> (there is also a testyTastery.py in the top level directory).  However, when I change line 2 to <code>bundlePath = sys.path[1]</code> (because builds in PyInstaller put the top level directory in sys.path[1], at least in Windows, sys.path[0] points to a base_library.zip that PyInstaller creates) and build this into a folder bundle for PyInstaller (making sure to either copy <code>uploads/testyTastery.py</code> or include it in the <code>.spec</code> file), I get the message from the testyTastery.py script, not the uploads/testyTastery.py script.  </p>
  
  <p>Any idea on how to easily change this?  To be clear, the first two print statements result in the same output for both running it before and after compiling with PyInstaller, after changing the second line as mentioned.  </p>
  
  <p>I don't know, but maybe it has something to do with PyInstaller always looking at files it packages before looking in sys.path for imports?</p>
  
  <p>Edit:  To be clear, if I do a build with none of the files available, then put the files in the appropriate folders afterward, the import precedence is just like in the command line / IDE.  This suggests to me that files packaged by PyInstaller are higher up in the import hierarchy.</p>