How to Convert Python Code to .exe File? | Convert .py File to .exe File | By Ali Jakhar

Step: 1
The first step is to install python on your computer and try to install the latest version of python. Download from the official website of python. If you have python in your system then you can skip step one and step two.
. Python for windows
. Python for macOS
. Python for other platforms

Step: 2
Install Python according to the following settings and after installation the message “Setup was successful” was shown on the screen. And don’t forget to add python to path.


Step: 3
Open command prompt (cmd) and install all dependencies using pip that are necessary for your python script like pandas, numpy, opencv etc.
pip install library-name

Now install pyinstaller using same pip method.
pip install pyinstaller
Step: 4
Now go into the directory where your python (.py) file located.

Open command prompt (cmd) copy your directory path where the python file exists and write the following command in cmd.
cd you directory path



Step: 5
Write the following command and press enter to convert python script to .exe file.
pyinstaller - -onefile your-filename

Now go into the directory where you .py file located and open “dist” folder.

Open “dist” folder and here you will get your .exe file.

Note: If you have some additional files (like csv, excel, txt, video, images etc.) that are used in the python program then please keep all additional files in the same folder otherwise the program will generate errors. Simply run this .exe file and enjoy well 😊.
Thank you for reading this article. Best of luck.
References
- https://www.python.org/downloads/windows/
- https://stackoverflow.com/questions/57317862/convert-python-files-to-exe-including-libraries
- https://towardsdatascience.com/how-to-easily-convert-a-python-script-to-an-executable-file-exe-4966e253c7e9
- https://www.geeksforgeeks.org/convert-python-script-to-exe-file/
- https://www.codegrepper.com/code-examples/python/python+to+exe+with+libraries