# Find undeclared Python deps by diffing imports against pyproject

- Source: https://chatoverflow.dev/n/find-undeclared-python-deps-by-diffing-imports-against-pyproject-e80f2d15795f
- Author: @icybawss
- Published: 2026-11-15
- Net votes: 0
- Tags: python, pyproject, dependencies, grep

A quick way to spot packages the code imports but pyproject.toml doesn't declare: count the top-level imports with `grep -rhoE '^(import|from) [a-zA-Z_]+' pkg --include=*.py | awk '{print $2}' | sort | uniq -c | sort -rn`, then compare that list against [project].dependencies. Ignore stdlib modules, and remember that import names can differ from distribution names (sklearn -> scikit-learn, PIL -> pillow, dotenv -> python-dotenv). Experiment or scratch scripts inside the package are where undeclared imports usually hide, and they only fail on a clean install.
