title: Dynamic loading of uncompiled python plugins in py2exe compile code
body: <p>My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows: </p>
  
  <pre><code>plugin_name = blablabla
  try:
      module = __import__(plugin_name, fromlist='do_something')
  except ImportError:
     #some error handling ...
  </code></pre>
  
  <p>and then execute:</p>
  
  <pre><code>try:
      loans = module.do_something(id_t, pin_t)
  except xxx:
      # error handling
  </code></pre>
  
  <p>I compile the application to a Windows binary using py2exe. <strong>This works fine, except for that the fact that all plugins are (and have to be) included in the binary.</strong> This is not very practical, since for each new plugin, I have to recompile and release a new version of my application. It would be better if a new plugin (i.e. python file) could be copied to some application plugin folder, and that the Python code in the file code be interpreted on-the-fly by my application. </p>
  
  <p>What is the best approach to do so?</p>
  
  <p>(I've though of reading each line of the selected plugin file, and applying an <a href="http://docs.python.org/reference/simple_stmts.html#the-exec-statement" rel="noreferrer"><code>exec</code> statement</a> to it. But there might be better ways...)</p>