title: Having a python module, install its own dependencies before running
body: <p>A lot of software packages require users of the system to install a set of dependencies first before they can use the software. (This is a general question not specific to python, but I'll speak in context of python.). Can't we make the python module install its own dependencies before executing the code if the dependencies are not already installed. This should be doable with the help of <code>system</code> or <code>subprocess</code> calls but I rarely see people doing this.</p>
  
  <p>For example lets say <code>lib</code> is a python library that needs to be used in the python file <strong>main.py</strong>:</p>
  
  <pre><code>import os
  try:
      import lib
  except:
      os.system('pip install pdir')
      import lib
  
  # Can make use of lib now
  </code></pre>
  
  <p>Is there anything potentially wrong with this approach? Could doing something like this cause problems for big projects?</p>
  
  <p><strong>Note</strong>: The advantage here is that a user using the file does not have to install the dependencies separately, he can simply run <code>python main.py</code>. And the second thing that I realize is that such approach makes sense only when <code>virtualenv</code> is being used.</p>