Error using Pytesser: ** [WinError 2] The system cannot find the specified file **

I get this error: [WinError 2] The system cannot find the specified file only when I use pytesser to execute OCR. Here is my code snippet.

from PIL import Image
from pytesseract import *
image = Image.open('pranav.jpg')
print (image_to_string(image))****

Otherwise, when I use PIL to resize the image, I do not get this error.

+4
source share
5 answers

You do not need to edit pytesseract files. You can declare the path to your Tesseract installation inside your code as follows:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
+7
source

. tesseract : https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-ocr-setup-3.02.02.exe&

pytesseract.py. :

C:\Users\USERNAME\AppData\Roaming\Python34\-\pytesseract\pytesseract.py

( 60):

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'tesseract'

, pytesseract.exe, :

# CHANGE THIS IF TESSERACT IS NOT IN YOUR PATH, OR IS NAMED DIFFERENTLY
tesseract_cmd = 'c:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

.

+2

tesseract .

, .

+1
  • tesseract : https://github.com/UB-Mannheim/tesseract/wiki

    : tesseract-ocr-setup-3.05.01.exe tesseract-ocr-setup-4.0.0-alpha.20180109.exe(). .

  • pytesseract.py . C:\Users\User\Anaconda3\Lib\-\pytesseract.py

    EDIT THIS IF TESSACTAL IS NOT IN YOUR PATH OR IT IS EXACTLY tesseract_cmd = 'c: \ Program Files (x86) \ Tesseract-OCR \ tesseract'

  • add the following code to your code after importing pytesseract

    pytesseract.pytesseract.tesseract_cmd = 'c: \ Program Files (x86) \ Tesseract-OCR \ tesseract'

0
source

Set tesseract_cmd, pytesseract.pytesseract.tesseract_cmd, TESSDATA_PREFIX and tessdata_dir_config as follows:

from PIL import Image
import pytesseract
tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
pytesseract.pytesseract.tesseract_cmd = 'D:\\Softwares\\Tesseract-OCR\\tesseract'
TESSDATA_PREFIX= 'D:\Softwares\Tesseract-OCR'
tessdata_dir_config = '--tessdata-dir "D:\\Softwares\\Tesseract-OCR\\tessdata"'
print(pytesseract.image_to_string( Image.open('D:\\ImageProcessing\\f2.jpg'), lang='eng', config=tessdata_dir_config))
0
source

All Articles