How to convert python file to executable file

How to convert python file to executable file

covert python file to executable file

Introduction

Python files while transferring them to another computer will not run because some python programs may require additional libraries to be installed to work correctly to avoid. To converting the python file to an executable file. In this blog, we are going to see different ways to convert python files to executable files.

Requirements

Open the command prompt and enter this command


pip install pyinstaller

Then after installing, pyinstaller

1. Converting the python file to an executable file(with debugging screen)

open the folder where the python file needs to be converted

Screenshot (237).png

From there, open the command prompt.

then enter the following command


pyinstaller  .py

After that opening, there will be three new folders that will be created. In which open the build folder and open another folder inside, which there will be an executable file.

Screenshot (241).png

This is how you convert a python file to an executable file.

With the debugging screen, any error in code will be displayed on the debugging screen during the processing. If you don't want a debugging screen, then use the below method.

2. Converting the python file to an executable file (without debugging screen)

open the folder where the python file needs to be converted

Screenshot (237).png

From there, open the command prompt

then enter the following command


pyinstaller -w .py

Screenshot (238).png

After that opening, there will be three new folders that will be created. In which open the build folder and open another folder inside which there will be an executable file.

Screenshot (241).png

This is how you convert a python file to an executable file.

without the debugging screen, you won't get the black box while opening the application if you thoroughly check the python code before converting you won't have any problems, but if you are in the testing stage it is recommended to go with debugging mode because any error during program execution will not be visible. So it is recommended to, at the starting stage, go with the debugging screen method.

3. Converting the python file to an executable file with an icon

If you are creating games or applications using python, you may need an icon to identify the application to set an icon to the executable.

open the folder where the python file needs to be converted with the icon image in '.ico' Format

Screenshot (237).png

Then open the command prompt and enter the command and enter the following command


pyinstaller -w .py -i .ico

Screenshot (244).png

After that opening, there will be three new folders that will be created. In which open the build folder and open another folder inside which there will be an executable file.

Screenshot (245).png

This is how you convert a python file to an executable file with an icon.