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.
pkg_resources.DistributionNotFound: The 'click>=8.0' distribution was not
found and is required by my-cliCommon 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.
python -m pip install . # pulls declared dependencies
python -c "import pkg_resources; pkg_resources.require('my-cli')"Confirm the runtime environment
- Run
python -m pip listin the same step that fails to confirm the dependency is present. - Ensure the venv running the script is the one packages were installed into.
- Avoid
--no-depsunless 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.