Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I get this error: [WinError 2] The system cannot find the file specified, only when I use pytesser to do 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 change size of image, I do not get this error.

like image 529
Pranav V Avatar asked Jul 04 '15 06:07

Pranav V


2 Answers

You don't have to edit any pytesseract files. You can declare the path to your Tesseract installation inside your code like so:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
like image 112
elevated Avatar answered Oct 15 '22 21:10

elevated


I got the same error. You have to install tesseract from here: https://code.google.com/p/tesseract-ocr/downloads/detail?name=tesseract-ocr-setup-3.02.02.exe&

Then you have to edit the pytesseract.py file. In my case, this file is located in the folder:

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

Search the following lines (for me it's line 60):

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

and change it to the location, where your pytesseract.exe is located, in my case the line looks like this:

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

Now your code should work.

like image 23
Maecky Avatar answered Oct 15 '22 21:10

Maecky