Upgrade installed Python packages with pip

Review outdated packages, upgrade a compatible set in an isolated environment, and use a reproducible rebuild instead of assuming a freeze file is a complete rollback.

Best practices
Illustration of software components, data, and application workflows

Pip has no built-in upgrade --all command. Start with python -m pip list --outdated, choose a compatible set of updates, and test it in an isolated environment. Automatically upgrading everything can move unrelated applications and tools at the same time.

Inspect and upgrade a reviewed set

python -m pip list --outdated
python -m pip freeze > before-upgrade.txt
python -m pip install --upgrade requests flask
python -m pip check

Choose the actual packages and constraints from your project. pip check checks declared dependencies; run the test suite as well. Update pip itself separately when appropriate with python -m pip install --upgrade pip.

A requirements-based workflow is often easier to review: adjust the direct constraints, resolve a compatible set, and install it into a fresh environment. Do not simply strip every version from a frozen file; it may contain editable installs, direct URLs, markers, and indirect dependencies whose intent is not obvious.

Automate the list without parsing a display table

Current pip does not support --outdated --format=freeze. Use JSON. This cross-platform script requests all outdated names in one installation command, so they are considered together:

import json
import subprocess
import sys

result = subprocess.run(
    [sys.executable, "-m", "pip", "list", "--outdated", "--format=json"],
    check=True, capture_output=True, text=True,
)
names = [item["name"] for item in json.loads(result.stdout)]
if names:
    subprocess.run(
        [sys.executable, "-m", "pip", "install", "--upgrade", *names],
        check=True,
    )

Use it only in an environment where the complete candidate list has been reviewed and broad upgrades are intended. It does not retain your project's undeclared compatibility limits, coordinate other environments, or guarantee an atomic rollback. Passing arguments as a list avoids shell quoting and empty-input issues found in ad hoc pipelines.

Consider an interactive wrapper

The third-party pip-review tool provides an interactive workflow:

python -m pip install pip-review
pip-review --local --interactive

Its --auto mode removes the prompts and needs the same reviewed scope as an automatic script. The tool does not eliminate dependency conflicts; use the version and behavior approved for the environment.

Recover by rebuilding the environment

A freeze snapshot helps identify prior versions, but reinstalling it does not automatically remove newly introduced packages or restore external/native dependencies. Recreate a clean environment from the known-good declarations or lock, using compatible Python/platform versions and retained artifacts, then test before switching back.

FAQ

Can I use pip install --upgrade *?

No. Pip does not interpret * as all installed packages, and a shell may expand it into local filenames before pip even sees it.

Can I limit updates to a patch series?

Declare constraints, such as ~=2.31.0 for that release series, in the maintained dependency specification. The version is illustrative; select a supported series for the real project.

Does one install command guarantee the whole environment stays compatible?

No. Resolve and test the complete project requirements. Pip can report conflicts, but a package outside the requested dependency set or an undeclared runtime assumption can still be affected.

References: pip list, pip install, pip freeze, pip-review project.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting