Convert Python Script to Exe file

It’s been a while to move on python development on full time basis. Frankly speaking I love Python, because there are many open-source tools that can help you to make it your job easier.

So, Let’s get started.

In this article, I will show you how to create an executable file from your python scripts.

There are a few options available. You can check them on the following links;

1- Py2exe 

2-cx Freeze

3-PyInstaller

After trying all three different packages, my winner will be Pyinstaller. The reason is; PyInstaller supports all major operations systems. So, if you would like to deploy your application on multi OS, the process would likely to be same on these platforms. In addition, its very well documented and its up to dated and maintained actively.  The package supports all main GUI libraries PyQt4, PyQt5, PySide, Django, wxPython, matplotlib and others without having to handle plugins or external data files manually.

As I assume, you already installed Python 2.7 on your system.

Next, you can download PyInstaller from the following links;

Either from http://www.pyinstaller.org/

or you can clone the project files on the projects GitHub page

Github https://github.com/pyinstaller/pyinstaller

Open command line, and write the following command.

-> python setup.py install

PyInstaller

What to generate;

-D, –onedir : Create a one-folder bundle containing an executable (default)

-F, –onefile : Create a one-file bundled executable.

–specpath DIR : Folder to store the generated spec file (default: current directory)

–windowed: prevents a console window from being displayed when the application is run.

I just created a test page with Pyqt4. See the below screenshot.

pyqttest

Finally, the following commands will create an .exe file for your apps.

->pyinstaller –onefile –windowed easy.py

pyqt2exe2

The executable file is already created in the dist folder.

it’s that easy.  As always, if you have any questions, you

can reach me at hello@yakup.me

Leave a Reply

Your email address will not be published. Required fields are marked *