Recently it took me to make a small program under Windows. Previously, I could not develop under it.
The program itself is simple, it was written relatively quickly. Much more time was taken away by its assembly under Windows. It is clear that the selected tools (Python3 + Qt5) are not native, but universal, but it took me so much time to build.
Accordingly, I want to share the practice, maybe someone else will have to knock his forehead on this wall.
Under the cut, the instructions come out of how easy it is to build PyQt5 applications in single-file.exe that do not require an installer.
The most well-known solutions for my task - assembling python applications in .exe are: py2exe, cx_freeze, and pyinstaller. About each written a lot of things. But very often the authors sin with a hack - the program is easily and quickly assembled and started ... on the same computer. Needless to say that these are two big differences - the launch on the dev-environment and the user? And so it will work for me without any assemblies and dances with a tambourine. Also, which users will install Qt for themselves?
For each tool there is a tutorial. But each had its own problems: one did not start (the pyinstaller still supports the 3rd python in experimental mode), the other collected what it could not launch, the third didn’t collect anything for a long time, berating everything around.
After a long battle, py2exe was chosen.
The secret of success in the correct installation of components from the correct sources (I do not give direct links, since they are still obsolete, I write what to look for):
- Win XP 32-bit (or another, which you take for the base - I specifically took the oldest system)
- Python 3.4 - install from www.python.ord / download Windows x86 msi installer. You can immediately add C: \ Python34 \ to% PATH%
- PyWin32 - we put pywin32-219.win32.py3.4.exe with sf.net
- Qt5.5 - set from the official website qt.io. At the same time, the mingw4.9.2 compiler is installed.
- After installation, add C: \ Qt \ Tools \ mingw492_32 \ bin to% PATH%.
- Git for Windows - we need it anyway, we install it from git-scm.com
- PyQt5 - download and install riverbankcomputing.co.uk win32 x86 installer
- SIP - I still did not understand why, but the same riverbankcomputing.co.uk did not bother to assemble the service module, so we download win files, unpack, it is convenient to continue working in the Git Bash console:
- python configure.py -p win32-g ++
- mingw32-make.exe
- mingw32-make.exe install.
- Of course, the installation will not work (. Fortunately, we need to put only 3 files. We go with our hands to the sipgen / folder subfolder and copy sip.exe to C: \ Python34.
- Then go to ../siplib and
- copy sip.pyd c: \ python34 \ Lib \ site-packages
- strip /c/Python34/Lib/site-packages/sip.pyd
- Finally, copy the .h file:
- cp sip.h / c / Python34 / include /
- py2exe - install in the native way: python -m pip install py2exe
- pyreadline is the same: python -m pip install pyinstaller
- 7-Zip - from the site 7-zip.org download x86 exe
- 7-zip extra - useful add-ons we download from there, unpack it into the folder with the installed 7-zip folder. On conflicts txt-files can be hammered.
- Resource Hacker - download angusj.com - however, if you are not going to replace the default program icon with your own, then you will not need it. Or you can replace it with windres, which comes bundled with mingw - but I already had it done with RH.
')
I share my setup.py:
from distutils.core import setup import os, sys import py2exe from glob import glob import PyQt5 NAME="Proga" qt_platform_plugins = [("platforms", glob(PyQt5.__path__[0] + r'\plugins\platforms\*.*'))] data_files.extend(qt_platform_plugins) msvc_dlls = [('.', glob(r'C:\Windows\System32\msvc?100.dll'))] data_files.extend(msvc_dlls)
This is a minimum program. Now you can build the application itself:
python setup.py py2exe
At the output we get a folder with the finished prog in dist.
This is good, but not always convenient for users. You can set an installer creator on this folder, such as Inno Setup and get msi. In my case, it was necessary to ensure the operation of the program with minimal user rights - precisely without the right to install lib.
So I went ahead and packed into 1 file using 7-zip. The scheme is as follows: create a 7z-archive and a special SFX-head and config are docked to it. The head unpacks the archive into a temporary folder, looks into the config and launches the necessary exe-file. Going like this:
cat 7zS.sfx resources / config.txt Proga.7z> Proga.exe
You can specify
various options in the config file, I set the minimum:
;!@Install@!UTF-8! Title="Proga" RunProgram="Proga\\pyftp1.exe" ;!@InstallEnd@!
The only drawback is the ugly picture of the exe file - the standard unpacker. This is where we replace the picture with the one we need:
RESHACKER.exe -addoverwrite Proga.exe, Proga.exe, resources / favicon.ico, ICONGROUP, MAINICON, 0
In order not to suffer with this all in the console, I made a small Makefile:
Now you can very easily reassemble the program:
mingw492-make.exe clean all
Successes in assembly!
Tell us about your experience!