title: python paths and import order
body: <p>I really want to get this right because I keep running into it when generating some big py2app/py2exe packages. I have my package that contains a lot of modules/packages that might also be in the users site packages/default location (if a user has a python distribution) but I want my distributed packages to take effect before them when running from my distribution.</p>
  <p>Now from what I've read <a href="http://docs.python.org/using/windows.html" rel="noreferrer">here</a> <code>PYTHONPATH</code> should be the first thing added to <code>sys.path</code> after the current directory, however from what I've tested on my machine that is not the case and all the folders defined in <code>$site-packages$/easy-install.pth</code> take precedence over this.</p>
  <p>Could someone please give me some more in-depth explanation about this import order and help me find a way to set the environmental variables in such a way that the packages I distribute take precedence over the default installed ones?</p>
  <p>So far my attempt is, for example on Mac-OS py2app, in my entry point script:</p>
  <pre><code> os.environ['PYTHONPATH'] = DATA_PATH + ':'
   os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.path.join(DATA_PATH
                                                              , 'lib') + ':'
   os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.path.join(
                                  DATA_PATH, 'lib', 'python2.7', 'site-packages') + ':'
   os.environ['PYTHONPATH'] = os.environ['PYTHONPATH'] + os.path.join(
                            DATA_PATH, 'lib', 'python2.7', 'site-packages.zip')
  </code></pre>
  <p>This is basically the structure of the package generated by py2app. Then I just:</p>
  <pre><code> SERVER = subprocess.Popen([PYTHON_EXE_PATH, '-m', 'bin.rpserver'
                              , cfg.RPC_SERVER_IP, cfg.RPC_SERVER_PORT],
                              shell=False, stdin=IN_FILE, stdout=OUT_FILE, 
                              stderr=ERR_FILE)
  </code></pre>
  <p>Here <code>PYTHON_EXE_PATH</code> is the path to the python executable that is added by py2app to the package. This works fine on a machine that doesn't have a python installed. However, when python distribution is already present, its site-packages take precedence.</p>