Hello everyone. I am new to Python and focused about imports. I researched for a long time but could not solve the problem. My project structure is like below:
โโ src
โโโ app
โ โโโ api
โ โ โโโ main.py
โ โ โโโ model
โ โ โโโ JobMatchResult.py
// JobMatchResult.py
from pydantic import BaseModel, Schema
class JobMatchResult(BaseModel):
and in main.py file i am importing JobMatchResult like:
from src.app.api.model.JobMatchResult import JobMatchResult
once i try to run server with command below:
uvicorn main:app --reload
i am getting error ModuleNotFoundError: No module named 'src'
Can anyone help me please?
this is not a FastAPI question, a good read would be https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html# it's extremely detailed how imports work, my guess is that in your main.py you should do just from model import JobMatchResult
@euri10 Thank for reply. I have read before link you. Also i read a few long articles about import statements in Python. I solved the problem 5 mins ago by writing command int terminal like:
uvicorn src.app.api.main:app
this is not a FastAPI question, a good read would be https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html# it's extremely detailed how imports work, my guess is that in your main.py you should do just
from model import JobMatchResult
Thanks for the help here @euri10 ! :clap: :bow:
Thanks for reporting back and closing the issue @tsdmrfth :+1:
Most helpful comment
@euri10 Thank for reply. I have read before link you. Also i read a few long articles about import statements in Python. I solved the problem 5 mins ago by writing command int terminal like:
uvicorn src.app.api.main:app