Create production build (executable) of a Python application

Himanshu Pratap
1 min readJun 23, 2024

--

PyInstaller is used to package Python code into standalone executable applications for various operating systems. PyInstaller analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files — including the active Python interpreter. This allows for easy distribution and deployment of Python applications, as the user does not need to have Python and any required modules installed on their system in order to run the application.

Note: PyInstaller generates Windows executable if it is run in windows environment. It generates linux executable if it is run in linux environment.

1. install pyinstaller
pip install pyinstaller

2. To check if pyinstaller is installed successfully,
pyinstaller --version

3. create executable. the execuatble will be unser dist directory
pyinstaller main.py

4. create single file executable
pyinstaller main.py --onefile

5. Changing executable name
pyinstaller main.py --onefile --name MyExecutable

6. If you want to hide the console window when running the executable file, you can use the — noconsole option:
pyinstaller --noconsole --onefile hello.py --name MyExecutable

Note: You might encounter some issues if You want to add underscores to executable file name.

There is another application auto-py-to-exe that is based on PyInstaller but provides GUI.

--

--

Himanshu Pratap
Himanshu Pratap

Written by Himanshu Pratap

System Administrator and Full stack web developer.

No responses yet