-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improving Windows with PyInstaller - Ocrmypdf Distribution Not Found #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you'll have to ask for support from the PyInstaller people, since I don't know much about it. ocrmypdf's use of cffi to access a C library, and its use of third party executables like Tesseract and Ghostscript, may be problematic for packaging. If you can identify a specific issue with ocrmypdf that is an obstacle to generating this installer, please open a PR. |
@jbarlow83 I it to run! I should have gone to pyinstaller first, so sorry about that. The fix can be found here: pyinstaller/pyinstaller#4809 I had to create hook files for both ocrmypdf module and the pikepdf module by using the --additional-hooks-dir HooksFolderPath flag. Thanks for the quick response. |
Would you mind sharing your full instructions? Maybe I'll be able to automate it one day. |
@jbarlow83
Having this hook alone will allow the app to run; however, it is not enough. In your program, once it attempts to execute the ocrmypdf.ocr() function, it will raise another error. I cannot remember what error it was exactly, but it was an error relating to a missing dependency within pikepdf. So the other script that you have to make is this: hook-pikepdf.py
Now when you package the main script with pyinstaller, you must include this flag: --additional-hooks-dir HooksFolderPath. |
Getting this error after following the instructions above: Traceback (most recent call last): can anyone help? |
@koolkunz Look up how to use pyinstaller with a project that uses pluggy as a plugin manager. pytest is an example of such a project. You may also need add ocrmypdf/builtin_plugins to the list of dynamic plugins that will be used - ocrmypdf installs some of its own plugins by default so that others can override them. |
This is all I had to do to get it working^. But now I have another small issue, that is if I am running my GUI application in no console mode, ocrmypdf keeps opening multiple console windows of tesseract (I think equal to the number of jobs being processed) and ghostscript executables with no output. I already have logging set to -1: Is there any other way to suppress these console windows from showing up at all? |
@koolkunz |
I'm still working on it and unless you want to distribute the exe you can just use ocrmypdf through simple python code or even just directly in the command line. |
I have the same problem, someone could help me? |
How can i disable the tesseract prompt? |
@koolkunz Have you found a way to prevent the console windows showing up? |
Unfortunately no, ultimately I just went with the console window option while building the exe using pynistaller |
If anyone does stumble into this extremely niche issue, a hotfix you can use is to monkey patch the subprocess.Popen() function that OCRmyPDF and its submodules (Tesseract and GhostScript) use to prevent them from opening new windows.
Note that its important that this block runs before importing ocrmypdf A more robust solution would be to add a flag to the .ocr function call that then passes on the flag to .Popen() |
Describe the bug
Pyinstaller was used to successfully create an executable file, but upon running the .exe, it crashes.
To Reproduce
To reproduce the error, make sure you flag --consoled when running the pyinstaller command. Then run the executable from the command prompt. Then it will raise pkg_resources.DistributionNotFound error.
Expected behavior
I expected all dependencies to be present.
Screenshots

System (please complete the following information):
Additional context
The .py script runs perfectly fine. There's just a problem with pyinstaller not finding the distribution.
The text was updated successfully, but these errors were encountered: