OCRmyPDF icon indicating copy to clipboard operation
OCRmyPDF copied to clipboard

Issue packaging with pyinstaller

Open kiyros opened this issue 2 years ago • 5 comments

below is my fileToOcr function

os.environ["TESSDATA_PREFIX"] = "Location of Tessdata Folder"
if __name__ == '__main__':
        start = timer()
        ocrmypdf.ocr(pdf, output_file=f'{outputPath}\\{pdfOriginalName.strip(".pdf").strip(".PDF")}.PDF',
        redo_ocr=True, output_type="pdf")
        end = timer()

        print(end - start, " Seconds")

        # Remove checked pdf from queue/check Folder
        os.remove(pdf)

This code runs fine inside visual studio but as soon as i package using pyinstaller pyinstaller --onefile --collect-data pikepdf --hidden-import pikepdf --copy-metadata pikepdf --collect-data ocrmypdf --hidden-import ocrmypdf --copy-metadata ocrmypdf -w 'dailyEDI_PDF_checker.py'

it gives me this error when i run the .EXE

  File "ocrmypdf\api.py", line 339, in ocr
  File "ocrmypdf\_validation.py", line 246, in check_options
  File "ocrmypdf\_validation.py", line 240, in _check_plugin_options
AttributeError: 'NoneType' object has no attribute 'languages'

I am not entirely sure why it is giving me 'noneType'

OS: Windows installed using: Pip Expected behavior: To run the ocr Function smoothly

kiyros avatar Oct 04 '22 14:10 kiyros

I believe you need to --hidden-import all of ocrmypdf's built in plugins because PyInstaller doesn't understand the plugin manager.

I did try creating a PyInstaller edition of ocrmypdf before but got worried about the time to maintain another build artifact.

jbarlow83 avatar Oct 04 '22 21:10 jbarlow83

By ocrmypdf's "Hidden imports" do you mean ghostscript, pngquant etc?

kiyros avatar Oct 17 '22 12:10 kiyros

No, I believe you need to specify --hidden-import ocrmypdf.builtin_plugins. Something along those lines.

I don't know of any way to use PyInstaller to bundle third party dependencies like Tesseract and Ghostscript, which have their own installers and license agreements.

jbarlow83 avatar Oct 17 '22 20:10 jbarlow83

I also encountered the same problem use --hidden-import ocrmypdf.builtin_plugins and --copy-metadata Unable to solve the problem, the same error will still occur

yang-521 avatar May 04 '23 17:05 yang-521

For anyone finding this topic through google, the probleme has been solved here (at least for me) : https://github.com/ocrmypdf/OCRmyPDF/issues/659#issuecomment-1517712600

mathieugruson avatar Dec 13 '23 12:12 mathieugruson