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

Python website

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.

installation setting
Install successfully

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
Example to install libraries

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 
click on bar to copy directory path
write cd and paste your path and press enter
Now you can see you are in the python file directory

Step: 5

Write the following command and press enter to convert python script to .exe file.

pyinstaller - -onefile your-filename
command to convert python file to .exe file

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

dist folder

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

Final .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.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ali Jakhar

Ali Jakhar

I’m a highly motivated and passionate programmer whose dream is to use my technical skill in Computer-vision/ deep learning/ AI to solve real- world problems.