title: Python: How can I override one module in a package with a modified version that lives outside the package?
body: <p>I would like to update one module in a python package with my own version of the module, with the following conditions:</p>
  
  <ul>
  <li>I want my updated module to live outside of the original package (either because I don't have access to the package source, or because I want to keep my local modifications in a separate repo, etc).</li>
  <li>I want <code>import</code> statements that refer to original package/module to resolve to my local module</li>
  </ul>
  
  <p>Here's an example of what I'd like to do using specifics from django, because that's where this problem has arisen for me:</p>
  
  <p>Say this is my project structure</p>
  
  <pre><code>django/
    ... the original, unadulterated django package ...
  local_django/
    conf/
      settings.py
  myproject/
    __init__.py
    myapp/
      myfile.py
  </code></pre>
  
  <p>And then in myfile.py</p>
  
  <pre><code># These imports should fetch modules from the original django package
  from django import models
  from django.core.urlresolvers import reverse
  
  # I would like this following import statement to grab a custom version of settings 
  # that I define in local_django/conf/settings.py 
  from django.conf import settings
  
  def foo():
    return settings.some_setting
  </code></pre>
  
  <p>Can I do some magic with the <code>__import__</code> statement in <code>myproject/__init__.py</code> to accomplish this? Is there a more "pythonic" way to achieve this?</p>
  
  <h2>Update - Why do I want to do this</h2>
  
  <p>Here's the scenario where I think this makes sense. </p>
  
  <ul>
  <li>I am launching a django powered website on a server that has django pre-installed globally. I can't modify the actual django source, in this case.</li>
  <li>My django project uses 3rd party reusable apps, and I don't want to change <code>imports</code> in all of those apps to import, for instance <code>mycustomsettings</code>. I want to leave the reusable apps blissfully ignorant that I have changed the implementation of django.conf.settings.</li>
  </ul>