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
Tesseract OCR doesn't work when Python script is converted to exe without console #5601
Comments
Does your program or any of its dependencies use |
I use multithreading for different processes and they are not related to Tesseract. Tesseract is linked to the main thread. I don't use |
Yep that's If you monkey patch your version of if include_stdout:
kwargs['stdout'] = subprocess.PIPE
else:
kwargs['stdout'] = subprocess.DEVNULL Then rerun your pyinstaller command but add the
That should fix it? |
I added the code above to the pytesseract codes in Virtual Environment and Default Environment library paths. They look like following:
I recreated the exe with |
Just to clarify - "Tesseract not working" means that in non-console mode, it throws an exception and you get the "Failed to execute script " dialog? (As opposed to not returning any data or returning different data than in console mode). If that's the case, let's try to find out what the error actually is: in your spec file under Alternatively, you can wrap your
calls in a try/except block and write the exception and its traceback into a file. |
@rokm I already tried to change debug option but it didn't work at all. As Iong as I understand If I want to see debug output I also have to activate the console mode but my problem is right here. If console mode is
Gave me an empty text file. |
What version of PyInstaller are you using? If you are using PyInstaller 4.2, then the try:
rec = pytesseract.image_to_data(processed, output_type='data.frame', config= config_)
except:
with open("error.txt", "w") as err:
err.write(sys.exc_info()[1]) If that gives you an error dialog again, it means that you're generating another exception in your exception handler. With PyInstaller 4.2 and You'll need to convert or format the Exception into string yourself. Or, use import traceback
traceback.print_exc(file=err) to get the traceback printed into your file. |
I have never suspected Pyinstaller version. I have used it for a long time without a problem. I have just checked it and its version is 3.6. I will update it and try again. |
I created a log of error as @rokm recommended. The debug mode is Here is the error:
|
It is indeed This |
Finally, it looks working now. When I test it fully I will close the issue. Thank you very much for your help.
|
I see you have submitted the fix for this issue to the |
I have an ML solution. I use Pytesseract in this solution. I need to create an executable from it. So I use the pyinstaller. To create an executable that can call another exe, the tesseract exe, I followed the https://stackoverflow.com/a/60679256/13080899. When I create the exe with console Tesseract exe is called in my exe and gives me output but if I create the exe without console Tesseract doesn't work. I couldn't find any solution. How can I solve the problem?
Here is the my .spec file:
P.S: Because of non-console mode I can't debug the exe.
The text was updated successfully, but these errors were encountered: