Skip to content
Latchkey

Python "pkg_resources.DistributionNotFound" at Runtime in CI

A package asked setuptools’ pkg_resources to confirm a dependency at runtime and it was not installed in the active environment. The metadata says the dependency is required, but the environment does not have it.

What this error means

A program or its entry-point script crashes with pkg_resources.DistributionNotFound: The X distribution was not found and is required by Y. It happens at import/startup, not during install - the environment is incomplete relative to what the package declares.

Python traceback
pkg_resources.DistributionNotFound: The 'click>=8.0' distribution was not
found and is required by my-cli

Common causes

A declared dependency was never installed

The package’s metadata requires a dependency that the active environment lacks - often because it was installed without its deps, or into a different environment.

Wrong or partial environment at runtime

The script runs under a different interpreter/venv than the one packages were installed into, so pkg_resources cannot find the required distribution.

How to fix it

Install the package with its dependencies

Install the project (and deps) into the environment that actually runs it.

Terminal
python -m pip install .        # pulls declared dependencies
python -c "import pkg_resources; pkg_resources.require('my-cli')"

Confirm the runtime environment

  1. Run python -m pip list in the same step that fails to confirm the dependency is present.
  2. Ensure the venv running the script is the one packages were installed into.
  3. Avoid --no-deps unless you install the dependencies separately.

How to prevent it

  • Install projects with their dependencies, not --no-deps, in CI.
  • Use one consistent venv for install and run.
  • Pin a lockfile so the runtime set matches what metadata requires.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →