Python Forum

Full Version: Converted EXE file size is too large
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have converted the python script to exe format using the below command, but the exe file size is too large. So when executing the exe file, it is taking a long time to start the execution. Could you please help us to solve this issue. Thanks in Advance.

pyinstaller.exe --onefile tiff-2-txt.py

Script File Size: 1.90 KB
Converted EXE file size: 153 MB

Python = 3.8
Pyinstaller Version = 5.8.0

import os.path
import cv2
import pytesseract



'''
- language will be defined in "lang.ini" file in the same path of input files.
- language code should be three digit iso code, multiple language should be add by separation of "+" symbol. e.g.: eng+hin
- Tesseract version 5 should be installed in "C:\Program Files\Tesseract-OCR"
'''
print("\n *********************************\n")
print("\n OCR Tool - Output: Text format\n")
print("\n Language code: Three letter iso code\n")
print("\n Multiple language: add by separation of ""+"" symbol. e.g.: eng+hin \n")
print("\n *********************************\n\n")

filepath1 = input(" Enter the File path: ")

filepath = filepath1 + "\\"

filelist = os.path.isdir(filepath)


for fname in os.listdir(filepath):
    if not fname.endswith(".tif"):
        continue
    path = os.path.join(filepath, fname) 
    print(path)
    pytesseract.pytesseract.tesseract_cmd=r'C:\Program Files\Tesseract-OCR\tesseract.exe'
    img = cv2.imread(path)  # load the image from the path using OpenCV library
    langu = filepath + "lang.ini"
    with open(langu) as f:   # open the ini file
        ini = f.read()       # read the ini file
    text = pytesseract.image_to_string(img, ini)    
    test = os.path.splitext(fname)[0]
    txtname = filepath + test + ".txt"
    f = open(txtname,"w+", encoding="utf-8")  
    f.write(text)
    cv2.waitKey(0)
    cv2.destroyAllWindows()


print("OCR Completed")