3 ms·
Python packaging is great. What's a bother is - as that article mentions - end-user deployments. Now, I sort of have that down to a tee by using cx_freeze and
by scarygliders 10y ago
Python packaging is great.
What's a bother is - as that article mentions - end-user deployments.
Now, I sort of have that down to a tee by using cx_freeze and Inno Setup, such that I can distribute my software to my end-users and all they have to do is click on a Setup.exe and my applications install just like any other Windows program.
I can do a similar thing on the Mac, but it's still a pain.
The main trouble with packaging Python applications up, is an apparent assumption (at least, that's the impression I have gotten over years of figuring out how to distribute my applications), that Python programs should all be open source - so for example, distutils assumes that the author wants his code to be readable by everyone who wishes to.
I wanted to be able to produce full applications and somehow compile and package them as in for e example, a C/C++ application.
The closest I can get to that currently, is cx_freeze, which isn't compilation, merely turning the Python code into bytecode.
Nuitka is showing lots of promise, but as yet it still cannot compile my applications into something usable (my really big Qt4 GUI applications either won't compile or there are lots of problems cropping up even if they do manage to run).
Here's hoping end-user deployment gets much easier than it is now, someday!
- yolesaber 10y agoCould you explicate on your end-user deployment workflow a bit? I'm building a game in python and would love to distribute .exes to Windows players
- ju-st 10y agopy2exe works well for me. It's no Windows installer but packaged in a zip file is good enough (for my use case at least). The only annoyance is the need to install some Microsoft C++ redistributables on the client side.
- scarygliders 10y agoSee my workflow - once you get it down to a tee, it becomes a very smooth workflow and a breeze to distribute in one convenient setup.exe.
- scarygliders 10y agoSure! 1) Develop your Python application ;) 2) I have a batch file build.bat which I use to build the deployment folder. This sits in the root directory of every application I develop, and is customised. It basically calls cx_freeze via the command line rather than bother with a setup.py file - I find this method far quicker and more convenient. An example... cxfreeze -OO -c CaptainsLog.py --include-modules lxml._elementpath,lxml.objectify,win32com.gen_py,requests.certs --base-name=Win32GUI --target-dir ..\CaptainsLog_DIST --icon CL_new_256.ico This is for my Captain's Log program - a 3rd party application for use with the game Elite: Dangerous cx_freeze will build and include all the necessary Python and Qt libraries to ..\CaptainsLog_Dist I've had to ensure cx_freeze included some required stuff like lxml and those other things because for various reasons it didn't automatically include them when they were not specified, so be aware of that possibility when attempting to freeze your application. 3) I then can test whether the build/distribution works by double-clicking on the captainslog.exe file which cx_freeze has produced. 4) If all is well, I then run Inno Setup. I have a file captainslog.iss which I use and change as required (e.g. new version number). This will basically take everything which is in the CaptainsLog_DIST folder, and package it up into a suitably named Setup.exe file. 5) I then sign the Setup.exe file with my code signing certificate. Search google for how to obtain such - basically you need at least a Class II certificate from a suitable provider to prove your identity. I use a utility called ksign to do the actual signing. 6) I test the Setup. 7) All going well, deployment to my users is simply providing a download location - notification is built into my application (check for new versions), or if they disable that, peruse the game forums or my web site. It's all been rather streamlined over a LOT of trial-and-error, frustration, and sometimes a lot of swearing. But the above works REALLY well for me and I use this workflow for bespoke software I write for paying customers. It's a similar workflow (with some differences) for Macs. The real beauty of it is that your end-users don't have to worry about installing Python, Qt, any of the Python dependencies/packages - everything required to run the application is provided. The other bonus is that you only need to worry about Python dependencies at /your/ end. Note: when developing and deploying my applications, my entire toolset is the 32-bit versions - this ensures that your package will install and run on both older 32-bit and newer 64-bit versions of your target O/S. Regards.
- yolesaber 10y ago
- witty_username 10y ago> The closest I can get to that currently, is cx_freeze, which isn't compilation, merely turning the Python code into bytecode. Is there a problem with that? If you're worried about someone stealing the code you can obfuscate it a bit.
- scarygliders 10y ago> Is there a problem with that? Yes - I wish I could compile my applications. Certain ones could benefit from being sped up a lot. I have used Cython before, on a pure Python program and using the --embed command, but it was a LOT of work to get that working (ended up having to take my Python program and merge everything into one monolithic Python file and feed that to Cython. And that meant taking the output from pyside-uic and bunging that in, as well as merging in the Resource file generated from pyside-rcc. I did that as an exercise. It worked, but was an awful lot of hard work and it was a horrifically hacky way to do it ;) At the same time I did also obfuscate things like the Licensing code that was in that file, in Python, beforehand. So yeah, it's not like I'm new to that sort of thing :) I just wish there was a more effortless way to do that - Nuitka has that promise but last time I checked it's just not there yet, despite the awesome work being done by Kay.
- witty_username 10y agoI have tested various Python implementations and pypy is the fastest, so you could create a self-extracting archive with pypy and your program. I created something similar to that here [1] for an abandoned project (but the project is not about self-extracting archives, so don't bother compiling the project). (1) https://github.com/RamchandraApte/unvanquished-installer/blob/master/xz_dec/xzminidec.c https://github.com/RamchandraApte/unvanquished-installer/blo...
- scarygliders 10y agoGood suggestion. I have looked at pypy in the recent past, but the showstopper is PySide isn't supported.
- gcr 10y agoPython is not a compiled language. Is there any reason not to write your app in Cython? Then you could compile it with your ordinary C compiler. Could be much harder to reverse engineer that way, if that's your concern.
- dozzie 10y ago/usr/bin/python and pyc/pyo files care to disagree.
- gcr 10y agoBy "compiled," I meant "down to native machine code," not to Python bytecode.
- scarygliders 10y agoYes, I know that :) My reply at https://news.ycombinator.com/item?id=12286806 https://news.ycombinator.com/item?id=12286806 is relevant. Regards