FileNotFoundError:[Errno 2]没有这样的文件或目录:'tesseract'

时间:2018-02-21 20:35:38

标签: python image-processing ocr

我已经使用

安装了tasseract
pip install pytesseract

每当我试图运行这段代码时

from PIL import Image
import pytesseract
im = Image.open('hasan1.jpg')
print (pytesseract.image_to_string(im))

我收到了这些错误。

 Traceback (most recent call last):
 File "ocr.py", line 34, in <module>
 text = pytesseract.image_to_string(Image.open(filename))
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 193, in image_to_string
 return run_and_get_output(image, 'txt', lang, config, nice)
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 140, in run_and_get_output
 run_tesseract(**kwargs)
 File "/home/hasans/.virtualenvs/cv/local/lib/python3.5/site-
 packages/pytesseract/pytesseract.py", line 111, in run_tesseract
 proc = subprocess.Popen(command, stderr=subprocess.PIPE)
 File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
 restore_signals, start_new_session)
 File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
 raise child_exception_type(errno_num, err_msg)
 FileNotFoundError: [Errno 2] No such file or directory: 'tesseract'

1 个答案:

答案 0 :(得分:0)

我相信PyTesseract要求你在你的系统上安装tesseract库 - PyTesseract正在尝试运行命令行界面,但它无法找到它,大概是因为你只安装了python绑定。

如果您使用的是基于Ubuntu / Debian的系统,可以尝试:

sudo apt-get install tesseract-ocr

您可以查看Tesseract安装文档以获取更多信息:https://github.com/tesseract-ocr/tesseract/wiki