Saturday, April 11, 2015

Bundling on Ubuntu

Poor old PyInstaller

OK so this morning I went back to the computer and into my Ubuntu VM and tried to get PyInstaller working. Several problems. Most dire, it aborts with the message "Security-Alert: try to store file outside of dist-directory". Quick duckduckgo search shows this has been encountered and probably fixed a few months ago, with code added to hook-distutils.py.

I realize yet again, that the Python3 branch of PyInstaller forked from the main line nearly a year ago, and it is missing a fair amount of maintenance. But I have no choice but to use it. It worked, more or less, on Mac OS, but now I'm hitting Ubuntu-related problems that have been fixed since the fork.

For example, the bug that stopped me last week on Ubuntu and entailed a lot of diagnosis and brain-sweat, the issue where the bundled app died looking "orig-prefix.txt"? I figured out how to fix it, and at one of the maintainers' request I opened an issue. Now I discover that it had been fixed some time ago on the main branch. So I closed the issue. What a waste of time!

I look at the current hook-distutils.py and think, heck, why not? So I copy its code and paste it in to replace the contents of the version I've got. Nope. When it runs, it wants things from compat.py that my version doesn't provide. Ohhhhh-kay, let's get the mainline version of compat.py. Nope. Very bad idea. It has several things that fail under Python3, it is Python-2 dependent. There's just too much divergence, I am not going to try to do a manual merge of the two branches.

cx_Freeze

Plan B, is to try cx_Freeze. So I pip-install it, or try to, and the install ends with a flock of error messages. I'm about to email their support list but I try one quick search and of course somebody has had the problem and offers a one-line edit of its setup.py to prevent it happening. Now I can't use pip to install it; I need to download it so I can edit setup.py. Which I do, and I do, and when I run the setup.py install, it runs.

So I run cxfreeze and it makes an app bundle, but just as with Mac OSX, it forgets to include QtWebKit (which is explicitly imported) and QtPrintSupport (which is not). Redo the bundle telling it to include those modules and ta-daaa, a working Ubundle!

Well, almost. It puts out an error message right away that tells me it has the old level of the natsort package, before Seth added the UNGROUPLETTERS option for me. So I upgrade that package, and the app still fails. Eh? Oh! I have to rebuild the bundle to pick up the new package! Doh! That done, it works.

Except for bookoupe, because I haven't installed that. But when I do, that works also, except for a stream of errors when the table is first built -- as reported earlier by bibimbop. Well, that'll be easy to fix. I've now noted several minor fixes that are needed. But I can zip through them Monday and have a working Ubuntu alpha bundle. Yay.

Before I do that I want to have just one little trial of Nuitka on Ubuntu. I think it may work on this platform, and if it does I want to know the difference in the bundle sizes.

Nuitka

So I installed Nuitka, which is a quick and simple process, except when you foolishly do the install from a different terminal window, one in which you have not "activated" your virtual environment. So Nuitka installs under Python 2.7 and into /usr/local/bin. So when it tries to compile a PyQt-using program, it can't find the PyQt modules.

So I spent ten minutes un-installing it (and, by the way, why does the standard setup.py not have an "uninstall" option??) and re-installing it in the virtual environment. Then I ran the compile and it died after several minutes with "virtual memory exhausted"!

So I had to shut down the VM and reconfigure it for more hard disk space. Now the compile is proceeding again. Nuitka is not fast, especially with a big program like PPQT.

OK, so it dies on the same damn assertion error that I just helped Kay fix in MacOS. It is screwing up getting the list of Qt plugins, except that I fixed the problem when it was generated by code specific to MacOS, code that ran the "otool" command and parsed its output. This would be going through a different subroutine, one for Linux, and I am not disposed to try to debug it. Fuck it. Nuitka is out as a Linux bundler. Cx_freeze rules here.

No comments: