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

pip.install('mypackage')

Does something like this exist?

By @mustafa on Mon 03 Sep 2018 |

Responses:

Offer your help. Be nice!

@mustafa
1

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!