3 ms·
> Why does it matter if a program is a self-contained binary? Because simple is better than complex. I'd rather download a binary than download a binary + depe
by bheadmaster 3y ago
> Why does it matter if a program is a self-contained binary?
Because simple is better than complex. I'd rather download a binary than download a binary + dependencies + set them up + bookkeep for when I want to delete all those files.
> Pyinstaller is pretty good for if you need a standalone installer.
PyInstaller doesn't work for many edge cases. If you're using a Python package that uses a compiled binary written in another language, good luck on your way down the rabbit hole of PyInstaller config. I personally could not succeed in packaging a uvicorn app, for example.
- redsaber 3y ago> I personally could not succeed in packaging a uvicorn app, for example. I kinda did managed to run a fastapi with uvicorn and pyinstaller. And I did nothing special
- bheadmaster 3y ago> 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") And ran "pyinstaller --onefile main.py" on it. The resulting binary, when executed, just says: Error loading ASGI app. Could not import module "main". Please share what exactly did you do that made it work. I already assume it's far from "nothing special"...
- imtringued 3y agoMy guess is that the main.py file is at the wrong location. Possibly dist/main.py aka dist.main:app.
- redsaber 3y ago#main.py from src.webserver import app import uvicorn if __name__ == '__main__': uvicorn.run( app, host='0.0.0.0', port=8080, ) #webserver 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) #create a python file for pyinstaller import PyInstaller.__main__ if __name__ == '__main__': name = "test" pyinstaller_list = [ 'main.py', f'--name={name}', '--clean', '--onefile', ] PyInstaller.__main__.run(pyinstaller_list) I remember reading this part 'main:app' where you should import the app instead for pyinstaller.
- bheadmaster 3y agoYou are right. I think I've misremembered the module name - it was uwsgi, not uvicorn. 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 https://github.com/pyinstaller/pyinstaller/issues/6362
- globular-toast 3y agoWe've had package managers for like, 30 years?
- bheadmaster 3y agoEach and every one of you?