2

I am getting the error TesseractError: (2, 'Usage: pytesseract [-l lang] input_file'). Using ! sudo apt install but still getting the error in colab. Its a JPG I am trying to read.

-----------------------------code -------------------------------------

! apt install tesseract-ocr
! apt install libtesseract-dev
! sudo apt install tesseract-ocr
! pip install Pillow
! pip install pytesseract
import pytesseract
import shutil
import os
import cv2
import random
from google.colab import files
from io import BytesIO
from PIL import Image,ImageFilter
!pip install pdf2image
!apt-get install -y poppler-utils
from pdf2image import convert_from_path
#from google.colab import drive
!sudo apt install tesseract-ocr
!pip install pytesseract
!pip install tesseract

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'
image_path_in_colab = 'Pillow block drawing.jpg'
img = cv2.imread('Pillow block drawing.jpg')
custom_config = r'-l eng --psm 6'
pytesseract.image_to_string(img, config=custom_config)
extractedInformation = pytesseract.image_to_string(Image.open(image_path_in_colab))
print(extractedInformation)
1
  • Hey, try changing pytesseract.image_to_string(img, config=custom_config) to pytesseract.image_to_string(img, lang='eng', config='--psm 6') Commented Jul 23, 2020 at 11:02

2 Answers 2

9

install:

!sudo apt install tesseract-ocr

Change:

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'

to:

pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
Sign up to request clarification or add additional context in comments.

Comments

1

you need to set the tesseract location as env variable . Like this

pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'

The following line is wrong

pytesseract.pytesseract.tesseract_cmd = r'/usr/local/bin/pytesseract'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.