title: Find *installed* Python module(s?) providing the imported functionality
body: <p>Given a bunch of Python files -- which can be standalone scripts or modules -- that run correctly on a machine, how can I find out the <em>minimal</em> set of Python modules I need to install on a clean machine?</p>
  
  <p>Basically I would like to compose a minimal <code>requirements.txt</code> or <code>install_requires</code> (for <code>setup.py</code>).</p>
  
  <p>E.g. if I have these imports:</p>
  
  <pre><code>import re
  from django.contrib.auth.models import User
  import json
  from sklearn import metrics
  import numpy as np
  import time
  import docx
  </code></pre>
  
  <p><code>re</code> and <code>time</code> are packages that come with Python, so nothing else is required.
  <code>django</code>, <code>sklearn</code>, and <code>numpy</code> could be fairly easily deduced since there is a matching package in <code>pip freeze</code>.
  <code>json</code> and <code>docx</code> are a problem ... for example, I have both <code>anyjson</code> and <code>jsonschema</code> installed and <code>python-docx</code> and <code>docx</code>. </p>