How can I install a pip package from a python script (programmatically)

I need to install some packages from inside a python script. Looking for something like this:

import pip


Does something like this exist?

By @mustafa on Mon 03 Sep 2018 |


Offer your help. Be nice!


As per Pip docs using the internal pip api is not recommended, instead just call it from python like you would call any command-line program:

import sys
import subprocess

subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'my_package'])
Login to leave a response!