1

I am having a problem with my project using Python 3 and Pytesseract. I want to recognize text from image but my code not work. I'm so sorry because my English not good. But I really need yours help!

Here is my code:

import pytesseract

from PIL import Image

print (pytesseract.image_to_string(Image.open('cc.jpg')))

And here is my problems:

C:\Python\python.exe C:/Users/Tam/Desktop/Test/test2.py

Traceback (most recent call last):
  File "C:/Users/Tam/Desktop/Test/test2.py", line 3, in <module>
    print (pytesseract.image_to_string(Image.open('cc.jpg')))

  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
    config=config)

  File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)

  File "C:\Python\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)

  File "C:\Python\lib\subprocess.py", line 997, in _execute_child
    startupinfo)

FileNotFoundError: [WinError 2] The system cannot find the file specified

Process finished with exit code 1

I don't understand what's wrong!

Emiliano Viotti
  • 1,619
  • 2
  • 16
  • 30
Tam Nguyen
  • 21
  • 5
  • 1
    `cc.jpg` probably doesn't exist. But please format your code so we can read it more clearly - at the moment it's a mess and we can't tell what you're indenting. – Shadow Nov 14 '17 at 03:16
  • Thanks for your help but I know actually that cc.jpg is exist – Tam Nguyen Nov 14 '17 at 03:28
  • It looks like the image can't be opened. I'd recommend using an absolute path for the image. At the moment it's relative to where the script was started. – AndrewS Nov 14 '17 at 03:28
  • 1
    Now that your code is formatted - I think it's more likely that the tesseract library may not be correctly installed... – Shadow Nov 14 '17 at 03:29
  • Thanks AndrewS, I have already used absolute path but it not work with me :) – Tam Nguyen Nov 14 '17 at 03:36
  • Shadow, what should I do now? – Tam Nguyen Nov 14 '17 at 03:37
  • Paul Rooney, my image and my script are in the same directory, but i don't understand what's happen – Tam Nguyen Nov 14 '17 at 03:39
  • ok split the `Image.open` and `pytesseract.image_to_string` into two lines. This will make it clear which one is causing the error. It may not be `cc.jpg` that is the file that cannot be opened. I tried it and that script works absolutely fine for me. – Paul Rooney Nov 14 '17 at 03:40
  • Paul Rooney, thanks for your help, I have tried it but it still the same error :( – Tam Nguyen Nov 14 '17 at 03:45
  • Sounds like an installation error. Try removing and reinstalling. – Paul Rooney Nov 14 '17 at 03:47
  • I have tried to run command: pip uninstall pytesseract and then run pip install pytesseract but it still has error. I am using windows 8.1 and python 3.6. What should I do now? Can you help me? – Tam Nguyen Nov 14 '17 at 04:11
  • This question seem the same your issue: [Try this one](https://stackoverflow.com/questions/44821838/file-tesseract-exe-does-not-exist) – JerryB Nov 14 '17 at 05:18
  • Thanks JerryB, I have known what's happened. :) – Tam Nguyen Nov 14 '17 at 09:39
  • For people who have a same problem with me, please visit http://digi.bib.uni-mannheim.de/tesseract/tesseract-ocr-setup-3.05.01.exe, then change cmd in pytesseract file. – Tam Nguyen Nov 14 '17 at 09:41
  • 1
    Possible duplicate of [File tesseract.exe does not exist](https://stackoverflow.com/questions/44821838/file-tesseract-exe-does-not-exist) – Aran-Fey Nov 14 '17 at 11:36

0 Answers0