You can try using the following Python code. Unlike pip freeze, this will not print warnings and FIXME errors.
For pip < 10.0.1, try this:
import pip
from subprocess import call
packages = [dist.project_name for dist in pip.get_installed_distributions()]
call("pip install --upgrade " + ' '.join(packages), shell=True)
And, For pip >= 10.0.1, try this:
import pkg_resources
from subprocess import call
packages = [dist.project_name for dist in pkg_resources.working_set]
call("pip install --upgrade " + ' '.join(packages), shell=True)