title: Execute a Python script post install using distutils / setuptools
body: <p>I'm trying to add a post-install task to Python distutils as described in <a href="https://stackoverflow.com/questions/1321270/how-to-extend-distutils-with-a-simple-post-install-script/1321345">How to extend distutils with a simple post install script?</a>. The task is supposed to execute a Python script <em>in the installed lib directory</em>. This script generates additional Python modules the installed package requires.</p>
  
  <p>My first attempt is as follows:</p>
  
  <pre><code>from distutils.core import setup
  from distutils.command.install import install
  
  class post_install(install):
      def run(self):
          install.run(self)
          from subprocess import call
          call(['python', 'scriptname.py'],
               cwd=self.install_lib + 'packagename')
  
  setup(
   ...
   cmdclass={'install': post_install},
  )
  </code></pre>
  
  <p>This approach works, but as far as I can tell has two deficiencies:</p>
  
  <ol>
  <li>If the user has used a Python interpreter other than the one picked up from <code>PATH</code>, the post install script will be executed with a <em>different</em> interpreter which might cause a problem.</li>
  <li>It's not safe against dry-run etc. which I might be able to remedy by wrapping it in a function and calling it with <code>distutils.cmd.Command.execute</code>.</li>
  </ol>
  
  <p>How could I improve my solution? Is there a recommended way / best practice for doing this? I'd like to avoid pulling in another dependency if possible.</p>