Force python to ignore pyc files when dynamically loading modules from filepaths
<p>I need to import python modules by filepath (e.g., "/some/path/to/module.py") known only at runtime and ignore any <code>.pyc</code> files should they exist.</p>

<p>This <a href="http://stackoverflow.com/q/3503970/226037">previous question</a> suggests the use of <code>imp.load_module</code> as a solution but this approach also appears to use a <code>.pyc</code> version if it exists.</p>

<p><strong>importme.py</strong></p>

<pre><code>SOME_SETTING = 4
</code></pre>

<p><strong>main.py:</strong></p>

<pre><code>import imp
if __name__ == '__main__':
    name = 'importme'
    openfile, pathname, description = imp.find_module(name)
    module = imp.load_module(name, openfile, pathname, description)
    openfile.close()
    print module
</code></pre>

<p>Executing twice, the <code>.pyc</code> file is used after first invocation:</p>

<pre><code>$ python main.py 
&lt;module 'importme' from '/Users/dbryant/temp/pyc/importme.py'&gt;

$ python main.py 
&lt;module 'importme' from '/Users/dbryant/temp/pyc/importme.pyc'&gt;
</code></pre>

<p>Unfortunately, <code>imp.load_source</code> has the same behavior (from the docs): </p>

<blockquote>
  <p>Note that if a properly matching byte-compiled file (with suffix .pyc
  or .pyo) exists, it will be used instead of parsing the given source
  file.</p>
</blockquote>

<p>Making <em>every</em> script-containing directory read-only is the only solution that I know of (prevents generation of <code>.pyc</code> files in the first place) but I would rather avoid it if possible.</p>

<p>(note: using python 2.7)</p>
