【问题标题】:FastAPI is trowing an import module error on import main moduleFastAPI 在导入主模块时出现导入模块错误
【发布时间】:2021-10-24 07:09:15
【问题描述】:

ASGI 无法导入模块 ma​​in 当我运行 uvicorn main:app --reload 我不明白为什么

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "first test"}

错误

NFO:     Will watch for changes in these directories: ['/Users/sonter/Documents/main.py']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [55716] using statreload
ERROR:    Error loading ASGI app. Could not import module "main".

【问题讨论】:

    标签: python frameworks fastapi uvicorn


    【解决方案1】:

    只需确保您没有将文件 ma​​in.py 保存在应用程序内的任何文件夹中。将主文件直接保存在应用文件夹中,否则应用将无法找到模块

    示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 2018-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多