brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: pip check finds broken or conflicting dependencies in an environment

Python
~/tips/tip-python-pip-check-broken-dependencies

python -m pip check, then fix what it names

Verifies that the installed packages have the dependencies they need, at compatible versions.

Installing one package at a time is how a Python environment slowly drifts into a state where two libraries want different versions of a third. pip check tells you whether you got there.

python -m pip check, then fix what it names

When everything is fine it prints No broken requirements found. and exits with 0. When something is off it names the problem, for example a package that needs another package which is not installed, or one that wants a version that differs from the one you have. Then the exit code is 1.

The exit code makes it a good last step in a Dockerfile or a CI job, right after the dependencies are installed. A build that fails here is better than one that fails on the first import in production.

Using python -m pip instead of plain pip makes sure you check the environment of the Python you mean, which matters when you have several on one machine.

The caveat is its scope. It only looks at what is installed right now. It does not tell you whether a requirements.txt would resolve, and it does not fix anything, it only reports. To repair a conflict you still have to pick versions yourself, or reinstall with a resolver run that sees all the requirements together.

Further reading: pip documentation: pip check

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link