title: Retrieving the requirements of a Python single script
body: <p>I would like to know how to extract the requirements from a single python script. I tried the following way, at the beginning of my file, immediately after the imports:</p>
  
  <pre><code>try:
      from pip._internal.operations import freeze
  except ImportError:  # pip &lt; 10.0
      from pip.operations import freeze
  
  x = freeze.freeze()
  for p in x:
      print(p)
  </code></pre>
  
  <p>The piece of code above, however, gives me back all the Python frameworks installed locally. I would like to extract <b>only</b> the necessary requirements for the script, in order to be able to deploying the final application. <br>
  I hope I was clear.</p>