ModuleNotFoundError: No module named 'app.routes'
ModuleNotFoundError: No module named 'app.routes'
所以我现在正在学习 fastapi 并且我试图将我的项目分成多个文件但是当我这样做时我得到了这个错误。
ModuleNotFoundError: No module named 'app.routes'
我已经阅读 This 很多遍了,我很确定我做的每件事都是正确的 谁能告诉我我哪里做错了吗?
app
│ main.py
│ __init__.py
│
└───routes
auth.py
__init__.py
main.py
from fastapi import FastAPI
from app.routes import auth
app = FastAPI()
app.include_router(auth.router)
auth.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/test")
async def test():
return {"test": "test"}
我运行uvicorn main:app --reload
你的 uvicorn 命令有点不对劲。从上面的任何目录 app
运行 --
uvicorn app.main:app --reload
好的,我在 github 上询问过,他们能够修复它。
Post: https://github.com/tiangolo/fastapi/issues/3602
只需 运行 命令下方
导出 PYTHONPATH=$PWD
所以我现在正在学习 fastapi 并且我试图将我的项目分成多个文件但是当我这样做时我得到了这个错误。
ModuleNotFoundError: No module named 'app.routes'
我已经阅读 This 很多遍了,我很确定我做的每件事都是正确的 谁能告诉我我哪里做错了吗?
app
│ main.py
│ __init__.py
│
└───routes
auth.py
__init__.py
main.py
from fastapi import FastAPI
from app.routes import auth
app = FastAPI()
app.include_router(auth.router)
auth.py
from fastapi import APIRouter
router = APIRouter()
@router.get("/test")
async def test():
return {"test": "test"}
我运行uvicorn main:app --reload
你的 uvicorn 命令有点不对劲。从上面的任何目录 app
运行 --
uvicorn app.main:app --reload
好的,我在 github 上询问过,他们能够修复它。 Post: https://github.com/tiangolo/fastapi/issues/3602
只需 运行 命令下方
导出 PYTHONPATH=$PWD