This is magic.
Leave it to ofek to tackle one of the toughest problems in Python!
Did you ever try pyinstaller?
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.
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!
That would solve a big problem in air-gapped environments :-)
- 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?
- 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/
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
[1] https://github.com/jart/cosmopolitan/issues/141#issuecomment... [2] https://github.com/delijati/docker-shiv#add-python-interpret...
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?
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 :)
1. I view that as out of scope but you can always embed your own distribution https://ofek.dev/pyapp/latest/config/#distribution-embedding
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.