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.
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'
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With