Anvil of Stars (Forge of God, #2)
Review:Yet another looooong slooooow build to... well, to not much. Not really a fun book, not really a deep book, not really much at all. Feels much longer than it is. |
Review:Yet another looooong slooooow build to... well, to not much. Not really a fun book, not really a deep book, not really much at all. Feels much longer than it is. |
I have written about this in the past, with the general conclusion being "it's a pain in the ass".
So, now, here is how it's done.
Start with a working PyQt application. In this example, I will use devicenzo.py mostly because:
It is a working PyQt application.
It uses a big chunk of PyQt
It's easy to test
Now you need a setup.py
. Here's one that works, with extensive commments.
# We will be using py2exe to build the binaries. # You may use other tools, but I know this one. from distutils.core import setup import py2exe # Now you need to pass arguments to setup # windows is a list of scripts that have their own UI and # thus don't need to run in a console. setup(windows=['devicenzo.py'], options={ # And now, configure py2exe by passing more options; 'py2exe': { # This is magic: if you don't add these, your .exe may # or may not work on older/newer versions of windows. "dll_excludes": [ "MSVCP90.dll", "MSWSOCK.dll", "mswsock.dll", "powrprof.dll", ], # Py2exe will not figure out that you need these on its own. # You may need one, the other, or both. 'includes': [ 'sip', 'PyQt4.QtNetwork', ], # Optional: make one big exe with everything in it, or # a folder with many things in it. Your choice # 'bundle_files': 1, } }, # Qt's dynamically loaded plugins and py2exe really don't # get along. data_files = [ ('phonon_backend', [ 'C:\Python27\Lib\site-packages\PyQt4\plugins\phonon_backend\phonon_ds94.dll' ]), ('imageplugins', [ 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qgif4.dll', 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qjpeg4.dll', 'c:\Python27\lib\site-packages\PyQt4\plugins\imageformats\qsvg4.dll', ]), ], # If you choose the bundle above, you may want to use this, too. # zipfile=None, )
Run python setup.py py2exe
and get a dist
folder full of binary goodness.
And that's it. Except of course, that's not it.
What this will do is create a binary set, either a folder full of things, or a single EXE file. And that's not enough. You have to consider at least the following:
Put everything in resource files: images, qss files, icons, etc. Every file your app needs? Put it in a resource file and load it from there. That way you don't have to care about them if you go the "one exe" road.
Compile .ui files to .py (same reason)
Figure out if you use Qt's plugins, and make them work. This includes: using Phonon, using QtSQL, and using any image formats other than PNG.
After you have that, are you done? NO!
Your windows user will want an installer. I am not going to go into details, but I had a good time using BitRock's InstallBuilder for Qt. It's a nice tool, and it works. That's a lot in this field.
But is that all? NO!
You have to take care of the Visual Studio Runtime. My suggestion? Get a copy of the 1.1MB vcredist_x86.exe (not the larger one, the 1.1MB one), and either tell people to install it manually, or add it to your installer. You are legally allowed (AFAIK) to redistribute that thing as a whole. But not what's in it (unless you have a VS license).
And we are done? NO!
Once you run your app "installed", if it ever prints anything to stderr, you will get either a dialog telling you it did, or worse (if you are in aything newer than XP), a dialog telling you it can't write to a log file, and the app will never work again.
This is because py2exe catches stderr and tries to save it on a logfile. Which it tries to create in the same folder as the binary. Which is usually not allowed because of permissions.
Solution? Your app should never write to stderr. Write an excepthook and catch that. And then remove stderr or replace it with a log file, or something. Just don't let py2exe do it, because the way py2exe does it is broken.
And is that it?
Well, basically yes. Of course you should get 4 or 5 different versions of windows to test it on, but you are pretty much free to ship your app as you wish. Oh, mind you, don't upload it to downloads.com because they will wrap your installer in a larger one that installs bloatware and crap.
So, there you go.
I have not posted in this blog in a long time.One ofthe reasons is that a whole lot of things have happened in my life, and I have not blogged about them.
It has gotten so that if I were to "catchup" here, I would need to post a 35-page post with 300 pictures, 100 code snippets, 50 rants and maybe 3 youtube videos.
So... screw that and let's pretend that was all a dream and that you (if there are still any "you" out there) have not been neglected, and all is good.
So, what am I posting about? Oh, just a short rant.
I am saddened and pissed off by people who proudly say "I don't know anything about X", where X is math, knitting, astrophysics, football, medicine, pet care, hairdressing, coffee brewing, politics, or dolphin-rearing (this doesn't apply to wine. It's perfectly ok not to care about wine, because most people who do care about wine are faking it).
There are tons of things I know nothing about. And you know what? Each one is a personal failure. Every time I see my mom knitting, and I simply cannot grasp how the hell it works, it pisses me off.
While it looks mind-crushingly boring, she's basically taking a string, make some knots using sticks, and producing a freaking sweater. How cool is that? I say pretty damn cool.
Whenever I see something that looks boring, or uninteresting, I always think, there is, somewhere, a person who has spent years of his life being the best at that. There is, somewhere, a person which is the world's authority on how to tie a string to make a sweater.
There is someone who is the non-plus-ultra of laying out coloured tiles so it looks good in the shape of a dolphin.
There is someone who is the best at using an incredibly inaccurate spraycan to draw on a wall.
There is someone who can look at a lot full of cars and tell you the logical order to remove them so they leave in minimum time.
There is someone who can hit a small ball, flying at 150km/h with a round stick, 1 out of every 3 times.
There is someone who can guess what word goes with almost every short definition.
There is someone who can tell you all regular spanish verbs that start with T.
There is someone who knows all about the history of journalism in Turkey (I actually walked in front of the Museum of Turkish Journalism, and it pains me that I couldn't go at the time).
There is someone who knows the dialog for every simpsons episode.
Every one of those things, and billions more, may be boring to me, but that is surely because I am failing at noticing the fun in it, it's a roughness of my soul, a failure of my perception, a flaw in my vision, which cripples me into saying they are all boring.
Boredom is not a sign of superiority, it's a sign of inferiority. Next time you see a bored person, someone that has nothing he wants to do, who looks condescendingly at those who are passionate about something, no matter what that may be, feel sad for him.