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'...