chuwy chuwy - 1 month ago 9
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

pypi.install('requests')
and requests will be installed into my virtualenv, and I should not type
pip install requests
in my shell?

Answer

You can also use something like:

import pip

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

# Example
if __name__ == '__main__':
    install('argh')
Comments