Search code examples
pythonqt4compilationexecutablepyqt4

How do I compile a PyQt script (.py) to a single standalone executable file for windows (.exe) and/or linux?


I started to fiddle with PyQt, and made a "beautiful" script from the pyqt whitepaper example app (pastebin)

It works perfectly in Windows and Linux (with qt environment already installed on both).

Now my question is: Since I am trying to use Qt because it is compiled (at least pure old C++ based Qt), how can I compile some .exe file to run it on Windows, or a standalone executable for Linux.

The point is that I want the program to be compiled, because of speed and portability, instead of interpreted from source, which would require a previous setup on any machine. One of the goals, for example, is sending small gui scripts via email to coworkers who are not programmers at all.


Solution

  • if you want completelly create one stand alone executable, you can try PyInstaller . i feel it's better to create one stand alone executable than cx_freeze or py2exe (in my experience). and easy to use (full documentation available in the site).

    It supports Python 3.6 or newer.

    Pass the --onefile argument if you want to create completely standalone .exe. in example :

    pyinstaller.exe --onefile --windowed app.py