How to make an executable file?

Question:

Code for the background image of the GUI :

bg = PhotoImage(file='images/all_button.png')
lbl_bg = Label(root, image=bg)
lbl_bg.place(x=0, y=0, relwidth=1, relheight=1) 
Error
Traceback (most recent call last):
  File "finalbilling.py", line 14, in <module>
  File "tkinter__init__.py", line 4061, in __init__
  File "tkinter__init__.py", line 4006, in __init__
_tkinter.TclError: couldn't open "images/all_button.png": no such file or directory
[7912] Failed to execute script finalbilling
Asked By: Rocky Sotto

||

Answers:

You can convert the python script to a standalone executable with all its dependencies included using different python packages. One such package is pyinstaller which can be used to create executable for Windows, Mac OS X, or GNU/Linux. pyinstaller

Answered By: cmp

There are many ways in which you can convert it into an executable program.
But one such easy way is to use pyinstaller.
Firstly, download a module named pyinstaller by entering the below code into your console:

pip install pyinstaller

Then, open the folder in which you have kept your program with console.

In windows, you can go to the folder and press shift key and right click to get the option to open with powershell.

In Mac, you can head to the folder > Right click on the folder > Click New Terminal at folder.

Then in the terminal you can either:

pyinstaller (name of your file).py

In this one you will get many other files associated with your executable program.
Don’t try to delete those files else your executable file may get affected.

Instead, try the below one to get only one executable file.

pyinstaller --onefile (name of file).py

You can get the executable program into dist folder of the folder you opened into console.

And then you can convert it to zip and send others.

If you are getting any type of errors like:
No such file or directory [7912] Failed to execute script finalbilling

Then there might be an issue with your script or while opening or importing any file an error occurred.
As the same happened with me and after resolving the issue in script it worked.

So, try to resolve the issue in script and then try the above steps it will definitely work.

Answered By: Harsh Master
pip install pyinstaller

pyinstaller --onefile main.py

OR

pyinstaller --onefile -w main.py # (will not work for console app)

-w means not to open CMD

Answered By: Niramay thaker