5 ms·
Show HN: PyApp – runtime installer for Python applications
- davins90 3y agoHi! It seems great! If I understood it well, does this allow to create an executable file for python file that, even if built on windows, can run on mac, linux, whatever.... right? in this way i can share my python code as an exe file that "not expert" can simply use by executing them on their machine, even if they don't have python installed... right? I'm wondering if this can work inside a docker container: at the moment I develop every project inside a docker container, each with its requirements.txt. file. Can I run this "pyapp" inside the docker (so Linux env) to create the exe file? Have I understood it well? Thanks very much!
- ofek 3y agoYou would have to compile the binary on the target platform. Eventually I will support cross compiling but even then there will still be one binary for every platform/architecture pair.
- holbue 3y agoLooks promising—thanks for sharing! Is it possible to include non-Python binaries somehow? Similar to how it is done with PyInstaller with the --add-binary argument? P.S.: It has already been mentioned, but I also find the "cowsay" example more confusing than informative. "cowsay" isn't even written in Python, but in Perl, isn't it? Maybe a simple hello-world.py example would work better :)
- ofek 3y agoThanks! 1. I view that as out of scope but you can always embed your own distribution https://ofek.dev/pyapp/latest/config/#distribution-embedding https://ofek.dev/pyapp/latest/config/#distribution-embedding 2. https://pypi.org/project/cowsay/ https://pypi.org/project/cowsay/
- dkroy 3y agoThis looks really useful. I would love to see some more end-to-end examples though it's nice to see the animated one right away in the readme.
- anze3db 3y agoThere are some configuration examples the docs[0] but since the project is still young there is probably room for improvements. Any particular that you'd like to see there? [0] https://ofek.dev/pyapp/latest/examples/ https://ofek.dev/pyapp/latest/examples/
- notatallshaw 3y agoAn example of running this on the command line that isn't a GIF.
- anze3db 3y agoThis bothered me as well and I've opened a PR to fix it: https://github.com/ofek/pyapp/pull/57 https://github.com/ofek/pyapp/pull/57
- pabe 3y agoHow does it differentiate from PyInstaller?
- deleted 3y ago[deleted]
- toyg 3y ago... or py2exe, cxFreeze...
- globular-toast 3y agoI wondered the same, then checked the source. The difference is this one is made with Rust.
- ofek 3y agoThe main difference is it does no build sorcery. In the end, your code is running on a real installation on disk. Therefore, there is no chance for extension modules to fail.
- seanthemon 3y agoDoes it potentially solve the problem of anti viruses false-flagging the runtime? Pyinstaller was giving me huge headaches with this
- ofek 3y agoYes.
- seanthemon 3y agoHallelujah, i'll give it a try over christmas break
- pantsforbirds 3y agoAre there any examples of PyApp using libraries that wrap other languages (Numpy, SpaCy, etc.)? In my experience, it has been extremely difficult to ship data/ml heavy applications built with Python as a binary.
- ofek 3y agoI think this is the most common pattern where you wish to execute a script based on a requirements file: https://ofek.dev/pyapp/latest/examples/#dependency-file-with-script https://ofek.dev/pyapp/latest/examples/#dependency-file-with...
- isoprophlex 3y agoHoly shit! So looking at the flowchart elsewhere in the docs, this means the executable produced by pyapp will ensure the requirements file is processed before executing the actual module code? This is magic.
- ofek 3y agoYes it will that is exactly correct! That particular example actually was after I was reading how to set up Stable Diffusion and other AI stack stuff.
- isoprophlex 3y agoI love this. This is exactly the idea the python ecosystem needs to unfuck it's packaging/distribution hell. I will start using this at work to try and solve the "how the hell do I distribute the spaghetti these devs produce in a sensible way" problem (we bundle dockerfiles atm and it's less than ideal) Will let you know if I have any avenues for potential improvement, etc.
- anze3db 3y agoThis looks really awesome! I'll try it out on some of my projects that I never tried to share outside of the Python community because setting up Python and/or pipx always felt too much of a hassle for end users. Leave it to ofek to tackle one of the toughest problems in Python!
- globular-toast 3y agoYou definitely shouldn't require users to install pipx and double definitely not Python. Pipx is good for dev tooling like tox et al, though. Did you ever try pyinstaller?
- ktm5j 3y agoI've had some success with pyinstaller but recently have been getting inconsistent results with an application I've written that uses pyside6. It was working for a while but all of a sudden the pyinstaller exe is giving an error that doesn't happen when I run the same code using python. Happened right before I had to go to the hospital (where I currently am) so I haven't had a chance to dig into it. But if this works reliably I'd be happy to switch.
- ofek 3y agoCan you please let me know how your experience is? Feel free to even open an issue on the repo!
- theemathas 3y agoPyinstaller doesn't work with python 3.12.0. You need to use python 3.12.1. https://github.com/pyinstaller/pyinstaller/issues/7992 https://github.com/pyinstaller/pyinstaller/issues/7992
- qubidt 3y agoHow does this compare to shiv? https://github.com/linkedin/shiv https://github.com/linkedin/shiv
- potatochup 3y agoShiv doesn't pack a python interpreter, it looks like this does
- ofek 3y agoYou can pack a Python interpreter but by default it downloads it (if not already cached)
- pacifika 3y agoHopefully it’s a bit faster than ptinstallers first run experience. That was the main reason I didn’t use it.
- delijati 3y agowill go on my "to try" list where i already have cosmopolitan [2]. my last setup (windows) was shiv + wine + nsis (used that as pyinstaller had some issues)[2] [1] https://github.com/jart/cosmopolitan/issues/141#issuecomment-1851643048 https://github.com/jart/cosmopolitan/issues/141#issuecomment... [2] https://github.com/delijati/docker-shiv#add-python-interpreter https://github.com/delijati/docker-shiv#add-python-interpret...
- ofek 3y agoPlease let me know how it goes!
- simonw 3y agoI don't fully understand the example in the GIF: - Why is it using Cargo if this is a Python tool? - How does it know that it should install "cowsay"? Is the only reference to cowsay that "export PYAPP_PROJECT_NAME=cowsay" line?
- ofek 3y ago- This is a tool to build binaries for Python applications. It could have just as been written in any other language that can produce binaries. - Yes that is correct, applications are configured at build-time with environment variables. For example, you could use just 2 environment variables like in that demo to build binaries for sqlite-utils. There are a bunch of examples of common use cases here: https://ofek.dev/pyapp/latest/examples/ https://ofek.dev/pyapp/latest/examples/ As far as how this works at runtime, I won't be able to explain any better than this Mermaid diagram I made: https://ofek.dev/pyapp/dev/runtime/#initialization https://ofek.dev/pyapp/dev/runtime/#initialization
- AndyKluger 3y agoThanks, I look forward to this! For some possibly useful documentation feedback: I got confused. Normally I would install a tool, check out its `--help` content, then maybe try it out. I think based on my attempts to do this and read the docs, is that this is not currently possible for PyApp. Instead you must have a Python app you'd like to setup for compilation before you can install PyApp at all (at least when using the cargo installation method). Is that right? And then when installing the tool it will also go ahead and compile the currently configured Python package?
- ofek 3y agoSorry about that! What you said is basically correct: this is for distributing Python applications. You configure via environment variables at build-time and the binary you ship to users who then run it. It could be a single name/version pair or more complex options like embedding a wheel or being defined by a requirements file.
- Gazoche 3y agoThis is really cool but I think the documentation could use a simple quickstart example, that takes actual Python code and shows how to turn it into an executable. Right now it feels a bit like reading a manpage, with tons of features and options but no clear way to get started. Definitely going to keep an eye on this, though. My company has been using pyInstaller to distribute Python tools and it's a bit of a PITA, so any alternative is welcome.
- chrooted-user 3y agoThis looks great, do I understand correctly that the full isolation option allows the binary to be fully self-contained and does not require any connectivity for the app to run? That would solve a big problem in air-gapped environments :-)
- ofek 3y agoYup that's right!
- chrooted-user 3y agoAwesome!!!