Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I need to install a package from PyPi straight within my script. Maybe there's some module or distutils (distribute, pip etc.) feature that allows me to just execute something like pypi.install('requests') and requests will be installed into my virtualenv.

1 Answer

0 votes
by (106k points)

To install a python module within code you can also use something like as follows:-

import pip

def install(package):

if hasattr(pip, 'main'):

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

else:

pip._internal.main(['install', package]) 

if __name__ == '__main__':

install('argh')

Related questions

0 votes
1 answer
asked Jul 26, 2019 in Python by selena (1.6k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 23, 2019 in Python by Eresh Kumar (45.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...