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

heltonbiker picture heltonbiker · May 4, 2011 · Viewed 71.3k times · Source

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.

Answer

Yuda Prawira picture Yuda Prawira · May 6, 2011

if you want completelly create one stand alone executable, you can try this : http://www.pyinstaller.org/ . 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).

Update: As latest information from @SoursopTree and @LectureMaker, it now support python version 3.3 - 3.6.

Update: pass --onefile argument if you want to create completely standalone .exe. in example :

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

Update: Another interesting library which Author of the library claims that you could Create cross-platform desktop apps. its worth to try https://build-system.fman.io/