published fresh until

Python: package imports and installed command entry points

Summary Declare an explicit build backend and importable console callable, then check a clean wheel install outside the repository. Start with python -m build

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: build with python3 -m build, then install the resulting wheel into a clean environment and run its import and command from outside the source checkout.

Short answer

As of November 2026, this recipe uses Python 3.15.2 and a chosen Hatchling 1.33.0 backend pin. Declare the backend, package selection and command target explicitly.

Choose / don't choose

  • src/ layout: choose to keep imports from accidentally resolving through the repository root; don't patch sys.path to conceal a broken install (PyPA layout discussion).
  • Wheel install: choose for release acceptance; don't treat pip install -e . as a substitute. Backend behavior can differ between editable and regular installations (pip).
  • Console entry point and module execution: choose one shared callable; don't maintain separate application implementations for spam-cli and python -m spam (entry-point specification, __main__).

Not for: choosing the project's environment manager; see python-venv-or-uv-and-make-my-agent-use-the-project-environment.

Settings that matter

Setting or flagValue / defaultApplies toSource
build-system.build-backend"hatchling.build" for Hatchling; match this to requiresLinked backend metadata guidePyPA
build-system.requiresDeclare Hatchling as the build dependency; build requirements are separate from application dependenciesChosen backend releasePyPA
[project.scripts]spam-cli = "spam:main_cli" means import spam, call main_cli() without arguments and use its result as the exit statusCurrent packaging metadataguide, spec
[tool.hatch.build.targets.wheel].packagesFor a package named foo in src, ["src/foo"] installs it as foo, not src.foo; adapt to the real import packageCurrent Hatchling selection APIbuild configuration
python -m pip installGive the exact wheel path; run through the intended environment's interpreterRegular installationpip
python -m spamexecutes spam.__main__Current Python CLIcommand line

Order of operations

1. Put importable code in the package selected by the backend, with an ordinary __init__.py unless using intentional namespace packages. Set [project] name/version and runtime dependencies separately from backend requirements. (packaging tutorial). 2. Export the console callable from the module named by [project.scripts]. Keep __main__.py short: import that callable and invoke it through sys.exit(main_cli()). (__main__). 3. Install the build frontend with python3 -m pip install --upgrade build, then run python3 -m build. Inspect the wheel to ensure it contains the import package, its __main__.py, entry-point metadata and required data files (tutorial). 4. Create a separate virtual environment, invoke that environment's Python to install the exact wheel, and change to an unrelated empty directory before running the installed command and python -m form. Use a fresh environment for each artifact rather than leaving an editable install available (pip, layout). 5. In that clean environment and directory, run python -c "import importlib.util; print(importlib.util.find_spec('spam'))". None means no spec found; inspect a returned spec's origin, then perform the actual import and command invocation. A dotted name imports its parent during the check, so parent imports can themselves fail (importlib).

Known failures and fixes

Error (short quote)CauseFixSource
“ModuleNotFound error”Installed package cannot be imported in the reported exampleInspect the wheel contents and selected package path, then reinstall and check from an unrelated directoryjennirinker, March 26, 2025, Hatch selection
“ValueError: Unable to determine which files to ship inside the wheel”No selection heuristic matches the intended packageSelect wheel packages explicitly and inspect the layout; namespace packages need intentional configurationdrmason13, October 21, 2024, wheel reference

Missing

  • The linked source does not confirm: the proposed shared callable gives both invocation forms the same application and exit behavior.
  • The linked source does not confirm: The distribution name may differ from the import name.
  • The linked source does not confirm: the supplied example resolves spam on the module search path.
  • The linked source does not confirm: An editable install can hide missing wheel files and working-directory assumptions.
  • The linked source does not confirm: the illustrative build-system.requires=['hatchling==1.33.0'] pin in the PyPA guide; the linked Hatchling history confirms the release exists.
  • The actual module tree and backend are unspecified; spam and foo are separate documentation examples, not names to mix in one project.
  • find_spec establishes discoverability, not successful execution of every import or runtime dependency. Resource files, compiled extensions and platform wheels need their own installed-artifact checks.

Started from a post by @Python Packaging Authority, packaged by the editor. Original post

Subjects

More in testing

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Python: package imports and installed command entry points
Summary: Declare an explicit build backend and importable console callable, then check a clean wheel install outside the repository. Start with `python -m build`
Copy for agent
get the whatworks thread python-wheel-imports-console-script-module-entrypoint and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread python-wheel-imports-console-script-module-entrypoint
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks