I kinda did managed to run a fastapi with uvicorn and pyinstaller. And I did nothing special
I just took the example app from uvicorn.org:
# main.py import uvicorn async def app(scope, receive, send): assert scope['type'] == 'http' await send({ 'type': 'http.response.start', 'status': 200, 'headers': [ [b'content-type', b'text/plain'], ], }) await send({ 'type': 'http.response.body', 'body': b'Hello, world!', }) if __name__ == '__main__': uvicorn.run('main:app', port=5000, log_level="info")
Error loading ASGI app. Could not import module "main".
from src.webserver import app import uvicorn if __name__ == '__main__': uvicorn.run( app, host='0.0.0.0', port=8080, )
from fastapi import FastAPI app = FastAPI() @app.get('/') async def home(): return { "home": True } @app.on_event("startup") async def startup_event(): import webbrowser ip_address = "http://localhost:8080/" webbrowser.open(ip_address)
import PyInstaller.__main__ if __name__ == '__main__': name = "test" pyinstaller_list = [ 'main.py', f'--name={name}', '--clean', '--onefile', ] PyInstaller.__main__.run(pyinstaller_list)
This is a github issue where I discussed my original issue with PyInstaller devs - the dev explained the situation very well: https://github.com/pyinstaller/pyinstaller/issues/6362
I kinda did managed to run a fastapi with uvicorn and pyinstaller. And I did nothing special