DEV Community

Alex Chen
Alex Chen

Posted on

Quick Tip: `python3 -m pip check` Catches Broken Dependencies Before Your Deploy Does

Quick Tip

After any pip install, run this before you commit:

python3 -m pip check
Enter fullscreen mode Exit fullscreen mode

It walks every installed package and verifies that all dependency constraints are actually satisfied. Zero output = your environment is consistent. Otherwise:

$ python3 -m pip check
urllib3 2.5.0 has requirement idna<4,>=2.5, but you have idna 4.1.
openai 1.99.0 has requirement httpx<1,>=0.23.0, but you have httpx 1.0.2.
Enter fullscreen mode Exit fullscreen mode

Why this matters more than it used to

Modern pip resolves at install time, but transitive upgrades drift. You install package-a in March, package-b in June upgrades a shared dependency, and nothing tells you package-a is now silently broken until import time in production.

Real example from last week: pip install --upgrade httpx (for an unrelated tool) broke my OpenAI client. pip check flagged it instantly:

# catch it in CI, not in prod
python3 -m pip check || exit 1
Enter fullscreen mode Exit fullscreen mode

The two-flag upgrade

# see which requirements AREN'T installed at all
python3 -m pip check --no-input

# combine with a quick audit of what's actually there
python3 -m pip list --format=freeze | sort > env.txt
Enter fullscreen mode Exit fullscreen mode

Add pip check to your pre-commit hook or CI step. It's built in, takes ~1.5 seconds on a 200-package venv, and catches the exact class of bug that otherwise shows up as ImportError in a deploy log.

Powered by MonkeyCode (free AI coding assistant): https://ly.cyberserval.tech/iIETXiF

What's in your CI pipeline that catches dependency drift — or do you find out from your users?

python #coding #tips

Top comments (0)