MutterCorp
MutterCorpNotice · Notícias
Programação·

Fix 'attempted relative import with no known parent package' for good

TL;DR ImportError: attempted relative import with no known parent package means Python ran your file as a script, so it has no package to resolve from .x import y against. The fix: cd to the directory that contains your package and run python -m myapp.cli, not python myapp/cli.py. With a src/ layout, pip install -e . once and -m works from anywhere. Python decides from the module's package, __spec__.parent (and the older __package__). Run as a file both are None, and run with -m the package is…

Publicado no Notice. Categoria: Programação.

Notícias sobre o mesmo assunto em outras fontes