Fastapi: ModuleNotFoundError: No module named 'src'

Created on 16 Sep 2019  ยท  3Comments  ยท  Source: tiangolo/fastapi

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?

question

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

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

All 3 comments

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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KoduIsGreat picture KoduIsGreat  ยท  3Comments

DrPyser picture DrPyser  ยท  3Comments

laith43d picture laith43d  ยท  3Comments

devtud picture devtud  ยท  3Comments

RogerioDosSantos picture RogerioDosSantos  ยท  3Comments