How to Make Executable File From Python (.Py to .Exe)
Convert Python Application to EXE
You can convert your application to EXE using the Pyinstaller application.
How to use?:
First, let’s load our program through PIP.
1 | pip3 install pyinstaller |
We installed our program.Later .let’s put our py files or files on the desktop or in another directory.Watch this here.the name of the directory to which you are exporting the py file should not contain Turkish characters.Now that we have prepared our files, let’s open a console screen(CMD) and switch to the code.
It says We want one file. All required Modules, etc. .he’il be buried in the EXE.
This says that our program will not produce console output.That is, clicking on our program will not be the console window.If your program produces console output, remove it.This is usually used in interface programs.
I’m sorry .in the py directory, type the source file of your program, along with the directory where it is located.
Exemplary:
1 | pyinstaller.exe --onefile --noconsole D:\programs\opensourceprojects.py |
The translation process may take a little longer and the file size may be large, which is inevitable.
Add Icon To The Python Program
First extension .we must have an icon file that’s the ICO..images such as PNG are not supported..if you have a PNG file, there are programs available on the web to convert it into an icon.My suggestion is any to icon program.
It’s time to add the icon.
We’re running our program this time.
1 | pyinstaller.exe --onefile --noconsole [.py folder] --icon [.ico folder] |
Like Example;
1 | pyinstaller.exe --onefile --noconsole D:\programs\opensourceprojects.py --icon D:\programs\osp.ico |
As you can see, it’s quite simple.Our program
1 | C:\your python version\lib\site-packages\pyinstaller\dist folder |
If you cannot find it there, it is in the dist folder under the directory you are converting to at the command prompt.