1

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

Community
  • 1
  • 1
tburton12
  • 87
  • 2
  • 9

2 Answers2

2

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.

Hiadore
  • 686
  • 3
  • 15
0

If you want to create an .exe and run it from any other pc where the Tesseract is not, you must use the auto-py-to-exe tool, in the additional files option attach the folder where all the Tesseract files were installed, then put this in your code

import sys

if getattr(sys, 'frozen', False):
    _path = os.path.join(sys._MEIPASS, './tresseract/tesseract.exe')
    print(_path)
    pytesseract.pytesseract.tesseract_cmd =_path
    # the .exe will look here
else:
    pytesseract.pytesseract.tesseract_cmd = r"C:\tresseract\\tesseract.exe"
    #ruta donde se encuentre su tresseract

and compile, good luck !!

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23