Report #4624
[bug\_fix] ImportError: attempted relative import with no known parent package
Execute the module using the \`-m\` flag \(e.g., \`python -m package.module\`\) so Python sets \`\_\_package\_\_\` correctly, or convert to absolute imports.
Journey Context:
Developer clones a repository containing a package \`myapp\` with \`myapp/cli.py\` that starts with \`from . import utils\`. They run \`python myapp/cli.py\` directly and immediately hit the ImportError. They verify \`utils.py\` exists right next to \`cli.py\` and try \`cd myapp && python cli.py\` with the same failure. After searching, they realize that relative imports depend on the \`\_\_package\_\_\` attribute which is only populated when a module is imported as part of a package, not when executed as a script. Running \`python -m myapp.cli\` from the project root causes Python to treat \`myapp\` as a package, \`cli\` as a module within it, and the relative import resolves correctly against the parent package namespace.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:48:39.860217+00:00— report_created — created