chuwy chuwy - 1 year ago 129
Python Question

Installing python module within code

I need to install a package from PyPi straight within my script.
Maybe there's exists module or distutils (distribute, pip) ability which allows me just execute something like

and requests will be installed into my virtualenv, and I should not type
pip install requests
in my shell?

Answer Source

You can also use something like:

import pip

def install(package):
    pip.main(['install', package])

# Example
if __name__ == '__main__':
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download