pythonpyinstallerpython-tesseract

How to compile Python code with PyTesseract to EXE?


I have working Python project which use pytesseract library. I tested it in PyCharm. Python ver. 3.7. Now I'm trying to compile this project to exe using PyInstaller.

When I run exe I got error:

File "getTextFromScreen.py", line 5, in ModuleNotFoundError:

No module named 'pytesseract' [9188] Failed to execute script main

My import in code looks like:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'Tesseract-OCR\tesseract'

I provide whole 'Tesseract-OCR' folder in python project folder and compiled project folder.

I don't know what do I do wrong. I want to ask you for help


Solution

  • Are you using windows? You must include the .exe extension in your path. Instead just r'Tesseract-OCR\tesseract', use r'Tesseract-OCR\tesseract.exe'. I have a project using PyTesseract too, provide a whole tesseract folder in python project and working well after compiled using PyInstaller.