Skip to main content


FULL PYTHON TO EXE TUTORIAL A to Z in one video. Create EXE with Python with Icon & Version info using pyinstaller

WATCH THE TUTORIAL FIRST


Building Executable

Run > CMD > pip install pyinstaller

pyinstaller.exe app.py
pyinstaller.exe --onefile app.py
pyinstaller.exe --onefile --windowed app.py
pyinstaller.exe --onefile --windowed --icon=app.ico app.py
pyinstaller.exe --onefile --windowed --icon=app.ico --version-file=version.txt app.py

Pyinstaller Error solutions:
https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages

Q. How to put application run at startup?
Ans.     a) Run > shell:startup [type enter]
            b) Create a shortcut and browse to your exe.

Note:- icon size should be 256x256.

1) console_app.py


import time

a = """
░░██░░
░█░░█░
█░░░░█
██████
█░░░░█
█░░░░█
█░░░░█
"""
b = """
█████░
█░░░░█
█░░░░█
█████░
█░░░░█
█░░░░█
█████░
"""
c = """
██████
█░░░░░
█░░░░░
█░░░░░
█░░░░░
█░░░░░
██████
"""
d = """
████░░
█░░░█░
█░░░░█
█░░░░█
█░░░░█
█░░░█░
████░░
"""
e = """
▓▓▓▓▓▓
▓░░░░░
▓░░░░░
▓▓▓▓▓▓
▓░░░░░
▓░░░░░
▓▓▓▓▓▓
"""
f = """
██████
█░░░░░
█░░░░░
██████
█░░░░░
█░░░░░
█░░░░░
"""
g = """
██████
█░░░░░
█░░░░░
█░░███
█░░░░█
█░░░░█
██████
"""
h = """
█░░░░█
█░░░░█
█░░░░█
██████
█░░░░█
█░░░░█
█░░░░█
"""
i = """
███████
░░░█░░░
░░░█░░░
░░░█░░░
░░░█░░░
░░░█░░░
███████
"""
j = """
███████
█░░█░░█
░░░█░░░
░░░█░░░
░░░█░░░
█░░█░░░
░██░░░░
"""
k = """
█░░░░█
█░░░█░
█░░█░░
███░░░
█░░█░░
█░░░█░
█░░░░█
"""
l = """
█░░░░░
█░░░░░
█░░░░░
█░░░░░
█░░░░░
█░░░░█
██████
"""
m = """
██░░░██
███░███
█░███░█
█░░█░░█
█░░░░░█
█░░░░░█
█░░░░░█
"""
n = """
██░░░░░█
█░█░░░░█
█░░█░░░█
█░░░█░░█
█░░░░█░█
█░░░░░██
█░░░░░░█
"""
o = """
██████
█░░░░█
█░░░░█
█░░░░█
█░░░░█
█░░░░█
██████
"""
p = """
██████
█░░░░█
█░░░░█
██████
█░░░░░
█░░░░░
█░░░░░
"""
q = """
██████░
█░░░░█░
█░░░░█░
█░░░░█░
█░░░░█░
█░░░██░
███████
"""
r = """
█████░
█░░░░█
█░░░░█
█████░
█░░░░█
█░░░░█
█░░░░█
"""
s = """
██████
█░░░░░
█░░░░░
██████
░░░░░█
░░░░░█
██████
"""
t = """
███████
░░░█░░░
░░░█░░░
░░░█░░░
░░░█░░░
░░░█░░░
░░░█░░░
"""
u = """
█░░░░█
█░░░░█
█░░░░█
█░░░░█
█░░░░█
█░░░░█
██████
"""
v = """
█░░░░░█
█░░░░░█
█░░░░░█
█░░░░░█
░█░░░█░
░░█░█░░
░░░█░░░
"""
w = """
█░░░░░█
█░░░░░█
█░░░░░█
█░░░░░█
█░░█░░█
█░█░█░█
░█░░░█░
"""
x = """
█░░░░█
█░░░░█
░█░░█░
░░██░░
░█░░█░
█░░░░█
█░░░░█
"""
y = """
█░░░░█
█░░░░█
██░░██
░████░
░░██░░
░░██░░
░░██░░
"""
z = """
██████
█░░░██
░░░██░
░░██░░
░██░░░
██░░░█
██████
"""
space = """
░
░
░
░
░
░
░
"""
#print(h.split())
#print(h[1:7],space[1:2],e[1:7])
#for i in h.split():
#        print(i)
#print(h.split()[1])

        
for word in range(0,7):
        A =  str(a.split()[word])
        B =  str(b.split()[word])
        C =  str(c.split()[word])
        D =  str(d.split()[word])
        E =  str(e.split()[word])
        F =  str(f.split()[word])
        G =  str(g.split()[word])
        H =  str(h.split()[word])
        I =  str(i.split()[word])
        J =  str(j.split()[word])
        K =  str(k.split()[word])
        L =  str(l.split()[word])
        M =  str(m.split()[word])
        N =  str(n.split()[word])
        O =  str(o.split()[word])
        P =  str(p.split()[word])
        Q =  str(q.split()[word])
        R =  str(r.split()[word])
        S =  str(s.split()[word])
        T =  str(t.split()[word])
        U =  str(u.split()[word])
        V =  str(v.split()[word])
        W =  str(w.split()[word])
        X =  str(x.split()[word])
        Y =  str(y.split()[word])
        Z =  str(z.split()[word])
        sp =  str(space.split()[word])
        #print(P+sp+Y+sp+T+sp+H+sp+O+sp+N+sp+sp+sp+T+sp+E+sp+S+sp+T)
        #print(P+sp+Y+sp+T+sp+H+sp+O+sp+N+sp+sp+sp+T+sp+E+sp+S+sp+T)  #comment this line for making it small
        print(H+sp+E+sp+L+sp+L+sp+O+sp+sp+sp+W+sp+O+sp+R+sp+L+sp+D)
        print(H+sp+E+sp+L+sp+L+sp+O+sp+sp+sp+W+sp+O+sp+R+sp+L+sp+D)
        print(H+sp+E+sp+L+sp+L+sp+O+sp+sp+sp+W+sp+O+sp+R+sp+L+sp+D)
time.sleep(5)



2) tk_app.py


import tkinter as tk

class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()

    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")

        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")

    def say_hi(self):
        print("hi there, everyone!")

root = tk.Tk()
app = Application(master=root)
app.mainloop()




3) PNG to ICO in Python.py


from PIL import Image

img_file = r'.png'
img = Image.open(img_file)
img.save('icon.ico',format = 'ICO', sizes = [(256,256)])




4) version form.py


#!/usr/bin/python
# -*- coding: utf-8 -*-
 
########################################################################
################### Sample format for reference ########################
########################################################################
#File Description = Python program App
#File Version = 1.1.1.1000
#Product Name = Python program App
#Product Version = 1,1,1,1000
#Legal Copyright = Copyright © reserved Joel Dcosta Ltd
#Company Name = Fuddy Duddies, Inc. 8 Flossie Dr. Arlington, VA 00001
#Internal Name = Python
#Legal Trademarks = Python is a Trademark of Python program App
#Original Filename = PythonApp.exe
########################################################################

################ Edit this only ########################################
file_description = "Python program TK App"
file_version = "1.1.1.1000"
product_name = "Python program TK App"
product_version = "1,1,1,1000"
copyright_ = "Copyright © reserved Joel Dcosta Ltd"
company_name = "Fuddy Duddies, Inc. 8 Flossie Dr. Arlington, VA 00001"
internal_name = "Python"
legal_trademarks = "Python is a Trademark of Python program App"
original_filename = "PythonApp.exe"
########################################################################
f_version = file_version.replace(".",",")


body = """VSVersionInfo(
   ffi=FixedFileInfo(
 # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
 # Set not needed items to zero 0.
 filevers=(%(f_version)s), 
 prodvers=(%(product_version)s), 
 # Contains a bitmask that specifies the valid bits 'flags' 
 mask=0x3f, 
 # Contains a bitmask that specifies the Boolean attributes of the file. 
 flags=0x0, 
 # The operating system for which this file was designed. 
 # 0x4 - NT and there is no need to change it. 
 OS=0x4, 
 # The general type of file. 
 # 0x1 - the file is an application. 
 fileType=0x1, 
 # The function of the file. 
 # 0x0 - the function is not defined for this fileType 
 subtype=0x0, 
 # Creation date and time stamp. 
 date=(0, 0)
 ), 
   kids=[ 
 StringFileInfo( 
  [ 
  StringTable( 
  u'040904b0', 
  [
                StringStruct(u'FileDescription', u'%(file_description)s'),
                StringStruct(u'FileVersion', u'%(f_version)s'),
  StringStruct(u'ProductName', u'%(product_name)s'),
  StringStruct(u'ProductVersion', u'%(product_version)s'),
                StringStruct(u'LegalCopyright', u'%(copyright_)s'),
  StringStruct(u'CompanyName', u'%(company_name)s'), 
  StringStruct(u'InternalName', u'%(internal_name)s'),
  StringStruct(u'LegalTrademarks', u'%(legal_trademarks)s'),
                StringStruct(u'OriginalFilename', u'%(original_filename)s'),
  ]) 
     ]), 
 VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) 
  ]
)
"""

f_version = file_version.replace(".",",")

print(body % {'file_description':file_description,
              'f_version':f_version,
              'product_name':product_name,
              'product_version':product_version,
              'copyright_':copyright_,
              'company_name':company_name,
              'internal_name':internal_name,
              'legal_trademarks':legal_trademarks,
              'original_filename':original_filename})

with open("t_version.txt","w",encoding='utf8') as f:
    f.writelines(body % {'file_description':file_description,
              'f_version':f_version,
              'product_name':product_name,
              'product_version':product_version,
              'copyright_':copyright_,
              'company_name':company_name,
              'internal_name':internal_name,
              'legal_trademarks':legal_trademarks,
              'original_filename':original_filename})




5) installer_exe.bat


pyinstaller.exe --onefile --icon="icon.ico" --version-file="t_version.txt" "2) tk_app.py"

Git:- https://github.com/joeldcosta/pyinstaller


🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Popular Posts

Python underline string, Python underline text, Underline python print

Python pip - Installing modules from IDLE (Pyton GUI) for python 3.7

Top 40 Python - String Processing in Python | Working with String in Python

Python Program - When was I born? / Date of Birth / MY BIRTHDAY (using Python3+)

Top 11 Essential Python Tips and Tricks





Subscribe to our Channel


Follow us on Facebook Page

Join our python facebook groups



Join us on Telegram