Skip to content

pip upgrade all packages

Sometimes, we want to upgrade all the python packages installed, the following python script can help to upgrade all the packages installed.

Python
import pkg_resources
from subprocess import call

packages = [dist.project_name for dist in pkg_resources.working_set]
for pkg_name in packages:
    call("pip install --upgrade " + pkg_name, shell=True)

If you want to upgrade a package with dependencies, then run the following command.

See doc https://pip.pypa.io/en/stable/development/architecture/upgrade-options/

Bash
pip install --upgrade --upgrade-strategy=eager <package name>