#python3
import pip
from subprocess import call
# pip version 9.0.1
#get_installed_distributions = pip.get_installed_distributions()
# pip version 10.0.1 plus
from pip._internal.utils.misc import get_installed_distributions
for dist in get_installed_distributions():
call("pip install --upgrade " + dist.project_name, shell=True)