bocdaz / template-python-project

A starter project template for new python project.
0 stars 0 forks source link

Templated FastAPI app relative import fails with "no known parent package" #17

Closed lucasmelin closed 2 years ago

lucasmelin commented 2 years ago
Traceback (most recent call last):
File "/app/src/eraseme_fastapi_template/main.py", line 11, in <module>
from .config import Settings, get_settings
ImportError: attempted relative import with no known parent package

Issue is caused when running the command we print out in the devspace_start.sh

https://github.com/bocdaz/template-python-project/blob/main/%7B%7Bcookiecutter.hyphenated%7D%7D/devspace_start.sh#L23

This is probably due to the fact that the PYTHONPATH ends up being set to src/eraseme_fastapi_template when main.py is run directly. The relative imports work as-is when the FastAPI application is run using poetry run dev however.