Python Language Example use of commands


Example

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:
    list.append(i.key)

pip.main(['install']+list+['--upgrade'])

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

for i in installed:
        pip.main(['install']+i.key+['--upgrade'])