Python Forum

Full Version: Python converted EXE not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have created a tool for OCR the content from the TIFF images and its working fine when executing from the source code.
However when executing the same from converted EXE it displayed the error message as below. Please help us to resolve this issue. Thanks in Advance...

Error Message from EXE:

Error:
Traceback (most recent call last): File "OCR.py", line 4, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ocrmypdf\__init__.py", line 13, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ocrmypdf\_version.py", line 16, in <module> File "importlib_metadata\__init__.py", line 1002, in version File "importlib_metadata\__init__.py", line 975, in distribution File "importlib_metadata\__init__.py", line 566, in from_name importlib_metadata.PackageNotFoundError: No package metadata was found for ocrmy pdf [4156] Failed to execute script 'OCR' due to unhandled exception![/color] [b]EXE Creator Command:[/b] pyinstaller --onefile OCR.py [b]System Details:[/b] Windows 7 64-bit [b]Version:[/b] Python 3.8 [b]ocrmypdf.exe version:[/b] 13.4.4
OCR Python Code:
import sys
import os
from PIL import Image
import ocrmypdf


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

filepath = filepath1 + "\\"

filelist = os.path.isdir(filepath)

langu = filepath + "lang.ini"

for fname in os.listdir(filepath):
    print(fname)
    if not fname.endswith(".tif"):
        continue
    input_file = os.path.join(filepath, fname) 
    im1 = Image.open(input_file).convert("RGB")
    pname = os.path.splitext(fname)[0]
    output_file = filepath + pname + ".pdf"
    f1 = open(output_file, "w+b")
    with open(langu) as f:   # open the ini file
        ini = f.read()       # read the ini file
    ocrmypdf.ocr(input_file, output_file, language=ini, force_ocr=True, output="pdf", jpeg_quality="100")
    f1.close()
(May-24-2022, 10:06 AM)Rajasekaran Wrote: [ -> ]I have created a tool for OCR the content from the TIFF images and its working fine when executing from the source code.
However when executing the same from converted EXE it displayed the error message as below. Please help us to resolve this issue. Thanks in Advance...

Error Message from EXE:

Error:
Traceback (most recent call last): File "OCR.py", line 4, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ocrmypdf\__init__.py", line 13, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module File "ocrmypdf\_version.py", line 16, in <module> File "importlib_metadata\__init__.py", line 1002, in version File "importlib_metadata\__init__.py", line 975, in distribution File "importlib_metadata\__init__.py", line 566, in from_name importlib_metadata.PackageNotFoundError: No package metadata was found for ocrmy pdf [4156] Failed to execute script 'OCR' due to unhandled exception![/color] [b]EXE Creator Command:[/b] pyinstaller --onefile OCR.py [b]System Details:[/b] Windows 7 64-bit [b]Version:[/b] Python 3.8 [b]ocrmypdf.exe version:[/b] 13.4.4
OCR Python Code:
import sys
import os
from PIL import Image
import ocrmypdf


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

filepath = filepath1 + "\\"

filelist = os.path.isdir(filepath)

langu = filepath + "lang.ini"

for fname in os.listdir(filepath):
    print(fname)
    if not fname.endswith(".tif"):
        continue
    input_file = os.path.join(filepath, fname) 
    im1 = Image.open(input_file).convert("RGB")
    pname = os.path.splitext(fname)[0]
    output_file = filepath + pname + ".pdf"
    f1 = open(output_file, "w+b")
    with open(langu) as f:   # open the ini file
        ini = f.read()       # read the ini file
    ocrmypdf.ocr(input_file, output_file, language=ini, force_ocr=True, output="pdf", jpeg_quality="100")
    f1.close()

Good day,

Have you managed to fix this problem. I am having the same issue.

Regards,
Hussein Ismail