Create production build (executable) of a Python application
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 pyinstallerpip install pyinstaller
2. To check if pyinstaller is installed successfully,pyinstaller --version
3. create executable. the execuatble will be unser dist directorypyinstaller main.py
4. create single file executablepyinstaller main.py --onefile
5. Changing executable namepyinstaller 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.