Creating an Executable from a Python Script

 

1. Make sure that you already have Python 2.7.x installed.

2. Install PyInstaller by using Pip, the Python package manager.

pip install pyinstaller

3. Building the Executable

pyinstaller.exe --onefile --windowed myapp.py

If the build was successful, the final executable, app.exe, and any associated files, will be placed in the dist directory, which will be created if it doesn’t exist.

Let me briefly describe the options that are being used:

  • --onefile is used to package everything into a single executable. If you do not specify this option, the libraries, etc. will be distributed as separate files alongside the main executable.
  • --windowed prevents a console window from being displayed when the application is run. If you’re releasing a non-graphical application (i.e. a console application), you do not need to use this option.

See the PyInstaller Manual for more configuration information.

4. Adding an Icon

pyinstaller.exe --onefile --windowed --icon=app.ico myapp.py

5. Adding Version Information

File (taken from the PyInstaller test suite) is used by PyInstaller to add version information to the executable. Save this file as version.txt.

pyinstaller.exe --onefile --windowed --icon=app.ico --version-file=version.txt myapp.py

Note:

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.3—3.5, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.

http://www.pyinstaller.org/


AUST IT - Computer help out of hours, when you need it most.

Find out why we do it for less.

About

AUST IT will help you resolve any technical support issues you are facing onsite or remotely via remote desktop 24/7. More...

Contacts

Reservoir, Melbourne,
3073, VIC, Australia

Phone: 0422 348 882

This email address is being protected from spambots. You need JavaScript enabled to view it.

Sydney: 0481 837 077

Connect

Join us in social networks to be in touch.

Newsletter

Complete the form below, and we'll send you our emails with all the latest AUST IT news.