Skip to content
Latchkey

setuptools "package directory does not exist" in CI

setuptools tried to collect a package from a directory that does not exist in the build tree. This usually means packages lists a name with no matching folder, or package_dir points at a src path that the manifest or checkout does not contain.

What this error means

The build fails with "error: package directory 'mypkg' does not exist" or "package directory 'src/mypkg' does not exist", naming a path setuptools expected but could not find.

setuptools
error: package directory 'src/mypkg' does not exist

Common causes

packages names a folder that is not there

You listed mypkg in packages, but the directory is named differently or lives under src/. setuptools looks where you told it and finds nothing.

package_dir and the real layout disagree

A package_dir = {"" : "src"} mapping expects code under src/, but the package sits at the repo root (or vice versa), so the resolved path is wrong.

How to fix it

Align package_dir with the actual layout

  1. Check where your package directory actually lives in the repo.
  2. Set package_dir and where to match that location.
  3. Re-run the build to confirm the path resolves.
pyproject.toml
[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

Confirm the directory is in the sdist

If building from an sdist, make sure MANIFEST.in or the build includes the package directory; a missing file in the tarball produces the same error.

Terminal
python -m build --sdist
tar tzf dist/*.tar.gz | grep mypkg/

How to prevent it

  • Keep package_dir/where in sync with the real folder layout.
  • Verify the sdist contains your package before publishing.
  • Use auto-discovery with a clean src layout to avoid manual path lists.

Related guides

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