1

I'm learning fastapi. I have a very simple project structure like this

.
├── __init__.py
├── database.py
├── main.py
├── models.py
├── requirements.txt
└── schemas.py

Inside main.py is

from fastapi import FastAPI
from typing import Optional
from . import schemas, models
from .database import engine

app = FastAPI()

# more code here...

but when I run this with uvicorn main:app --reload I get the error

...
from . import schemas, models
ImportError: attempted relative import with no known parent package

I don't understand why I'm getting this error. I'm loosely following this tutorial. I've also read through numerous related SO questions (1 2 3), but none seem to match my situation.

Ben
  • 17,762
  • 27
  • 102
  • 166

1 Answers1

1

Instead of importing the files as "from . import schemas, models", Try importing it directly like this - import schemas,models.I think this might work.

Sairam
  • 33
  • 5