5 ms·
Preamble: I like Python - it seems to fit my mental models well, and I'm productive writing in it. However, only just recently I tried to develop a more-than-tr
by gota 5y ago
Preamble: I like Python - it seems to fit my mental models well, and I'm productive writing in it. However, only just recently I tried to develop a more-than-trivial program to deploy as an executable for my Windows-using friends. This may sound naive, but I'd never thought about how hard it is, especially when mostly everything else in Python is well-tooled, well-documented, and works. If you check my post history you'll see I've been following this subject lately... in the hopes I won't have to re-write my stuff in C# or something. I got it done, but am thoroughly underwhelmed by the experience and the resulting size of the executable (due to cascading dependencies that I'd really rather not pick apart).
So here's the question - what's your take on how to package a Python program as an executable (wherein package does not mean Python package, but generate a click-and-run Windows executable)? Anything on that in the book? I can't tell from the 'Contents' list, but it seems not, right?
Congrats on the book. I'll take some time to go over the Extracts (and thanks for those, too!)
- nsomaru 5y agoNot OP, but I’ve had good success with pyinstaller and nuitka.
- muunbo 5y ago'Nuitka' might be what you're looking for
- gota 5y agoHey, I did try it - it was how I got it to work at all. Relatively simpler than the alternatives, IMHO, but still suffering from the large executable size due to dependency cascades I'm at peace, now, with having to prune and bound my imports to account for that. But it is a negative thing that I have to change my code from what it'd normally be to make it remotely passable... This is definitely a relatively smalln and maybe rare, but still a disadvantage of Python (that, in retrospect, I should've obviously have anticipated, so that's on me)
- mumblemumble 5y agoPerhaps https://pypi.org/project/treeshaker/ https://pypi.org/project/treeshaker/ can help with that?
- gota 5y agoI was not aware of this, thanks a lot! Will definitely look into it
- dmuller 5y agoHey - thanks for checking the book out. Yeah, you are correct---the book does not cover packaging a Python program as a click and run style executable. It's definitely a tricky problem. (Depending on the audience for the tools (e.g. if it's developers), one potential option might be to package your code in a Docker image and distribute it that way---although that's not without its own drawbacks.) Other commenters have posted potential tools to check out too.
- nanis 5y agoThe age old solution to this problem is to package the script plus the interpreter plus the dependencies in a glorified self-extracting ZIP file. E.g. [pp], [py2exe]. [pp]: https://metacpan.org/pod/pp https://metacpan.org/pod/pp [py2exe]:https://github.com/py2exe/py2exe https://github.com/py2exe/py2exe