Python Language Usage of "pip" module: PyPI Package Manager Example use of commands


import pip

command = 'install'
parameter = 'selenium'
second_param = 'numpy' # You can give as many package names as needed
switch = '--upgrade'

pip.main([command, parameter, second_param, switch])

Only needed parameters are obligatory, so both pip.main(['freeze']) and pip.main(['freeze', '', '']) are aceptable.

Batch install

It is possible to pass many package names in one call, but if one install/upgrade fails, whole installation process stops and ends with status '1'.

import pip

installed = pip.get_installed_distributions()
list = []
for i in installed:


If you don't want to stop when some installs fail, call installation in loop.

for i in installed: