Pyinstaller with fastapi and database

Viewed 256

folder structure

This is folder structure of my fastapi app. I am using sqlalchemy to connect to Postgres database. I am using uvicorn server.

In my main.py:

functions.models.Base.metadata.create_all(bind=engine)
tasks.models.Base.metadata.create_all(bind=engine)
app= FastAPI()
app.include_router(functions.main.router)
app.include_router(tasks.main.router)

if __name__ == "__main__":
    uvicorn.run(f"{Path(__file__).stem}:app", host='0.0.0.0', port=8127, workers=1)

I am trying to compile into exe with pyinstaller. This is my spec file, please advice what is wrong that main doesn't load:

a = Analysis(['main.py'],
             pathex=['...\\app'],
             binaries=[],
             datas=[],
             hiddenimports=['uvicorn.lifespan.off','uvicorn.lifespan.on','uvicorn.lifespan',
             'uvicorn.protocols.websockets.auto','uvicorn.protocols.websockets.wsproto_impl',
             'uvicorn.protocols.websockets_impl','uvicorn.protocols.http.auto',
             'uvicorn.protocols.http.h11_impl','uvicorn.protocols.http.httptools_impl',
             'uvicorn.protocols.websockets','uvicorn.protocols.http','uvicorn.protocols',
             'uvicorn.loops.auto','uvicorn.loops.asyncio','uvicorn.loops.uvloop','uvicorn.loops',
             'uvicorn.logging','app.database'],
             hookspath=['extra-hooks'],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='main')
0 Answers
Related