pytesseract OCR python 错误 - 示例代码



嗨,我尝试了解如何使用 pytesseract(https://pypi.python.org/pypi/pytesseract(,所以我运行示例代码:

try:
    import Image
except ImportError:
    from PIL import Image
import pytesseract
im=Image.open('test.png')
print(pytesseract.image_to_string(im))

但是我有错误:

Traceback (most recent call last):
  File "C:/Users/K/PycharmProjects/untitled/zad1.py", line 7, in <module>
    print(pytesseract.image_to_string(im))
  File "C:UsersKAppDataLocalProgramsPythonPython35-32libsite-packagespytesseract-0.1.6-py3.5.eggpytesseractpytesseract.py", line 161, in image_to_string
  File "C:UsersKAppDataLocalProgramsPythonPython35-32libsite-packagespytesseract-0.1.6-py3.5.eggpytesseractpytesseract.py", line 94, in run_tesseract
  File "C:UsersKAppDataLocalProgramsPythonPython35-32libsubprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "C:UsersKAppDataLocalProgramsPythonPython35-32libsubprocess.py", line 1220, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

我的python版本是3.5,pytesseract版本是0.1.6。我在Windows 7上工作。

我在 Ubuntu 上也遇到了这个问题。多亏了@Newbie,我在安装 tesseract 后解决了它。

sudo apt-get install tesseract-ocr
sudo apt-get install tesseract-ocr-chi-sim

看来

sudo pip install pytesseract

只安装 Python 接口而不是 tesseract 本身

以下是我的错误信息:

OSError                                   Traceback (most recent call last)
<ipython-input-4-aaddc46c52ee> in <module>()
----> 1 pytesseract.image_to_string(Image.open('./static/files/captcha'))
/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.pyc in image_to_string(image, lang, boxes, config)
    159                                              lang=lang,
    160                                              boxes=boxes,
--> 161                                              config=config)
    162         if status:
    163             errors = get_errors(error_string)
/usr/local/lib/python2.7/dist-packages/pytesseract/pytesseract.pyc in run_tesseract(input_filename, output_filename_base, lang, boxes, config)
     92 
     93     proc = subprocess.Popen(command,
---> 94             stderr=subprocess.PIPE)
     95     return (proc.wait(), proc.stderr.read())
     96 
/usr/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.
/usr/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1333                         raise
   1334                 child_exception = pickle.loads(data)
-> 1335                 raise child_exception
   1336 
   1337 
OSError: [Errno 2] No such file or directory

我解决了我的问题。解决方案非常简单:安装 Tesseract-OCR。

相关内容

  • 没有找到相关文章