Search code examples
pythongoogle-colaboratorypython-tesseract

Pytesseract image to string error messages in Colab


In my Colab installed and imported pytesseract as:

!pip install pytesseract
import pytesseract
import cv2

Load the image:

image = cv2.imread('drive/MyDrive/test.png')

Then I'll get this message: (2, 'Usage: pytesseract [-l lang] input_file') if I write code as:

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
text = pytesseract.image_to_string(image)

And this message: /usr/bin/tesseract is not installed or it's not in your PATH. See README file for more information. if I write:

pytesseract.pytesseract.tesseract_cmd = (r'/usr/bin/tesseract')
text = pytesseract.image_to_string(image)

Do you know why and how can I fix it? Please tell me if you need more information.


Solution

  • Just be sure you've installed the underlying library the Python module is taking advantage of, for example:

    !sudo apt install tesseract-ocr
    
    # then you can do: 
    !pip install pytesseract