Converting script to executable

What did I learn today?

Today, I discovered how to transform a Python script into an executable. There are two approaches: one involves using the command line interface (CLI), and the other employs a graphical user interface (GUI). We will now explore CLI method.


Python Library: pyinstaller Refer to the documentation for details.

Activate the virtual environment before running pyinstaller.

Step 1: install pyinstaller using pip:

  pip install pyinstaller

Step 2: package your script after installing pyinstaller, navigate to the directory containing your Python script, and run the following command:

pyinstaller --onefile --noconsole

This command:

  • The --onefile option bundles everything into a single file, simplifying distribution.

  • No console window appears when the application launches.

  • Ideal for finished GUI applications.


This command:

  • Creates a folder with an executable and dependencies.

  • Suitable for development and debugging.

After running this command, PyInstaller will create a 'dist' directory in the same location as your script. Within the 'dist' directory, you will find the standalone executable file, which will have the same name as your Python script.

Replace with the name of your Python script.

Be aware that PyInstaller includes the Python interpreter, which can increase the size of the executable. Additionally, the executable is specific to the platform it's created on; an executable made on Windows will not work on MacOS or Linux. To support different platforms, you must run PyInstaller on each one individually.