pytesseract:无法使用“Image.open"访问图像;《错误2》错误 [英] pytesseract: Can't access Image with "Image.open" "Errno 2" error

查看:35
本文介绍了pytesseract:无法使用“Image.open"访问图像;《错误2》错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试使用 pytesseract.我对 python 也不太满意.我在桌面上创建了一个名为 python_test 的新文件夹.我在 Mac 上.在这个文件夹中,我有一个 test.png 文件和一个 py 脚本:

I'm trying to use pytesseract for the first time. I'm also not so confortable with python. I've created a new folder called python_test on my desktop. I'm on Mac. In this folder I have a test.png file and a py script :

from pytesseract import image_to_string
from PIL import Image

print image_to_string(Image.open('test.png'))
print image_to_string(Image.open('test-english.jpg'), lang='eng')

所以从我的终端,我进入 python_test 文件夹然后我运行 python read.py 然后我有以下错误:

So from my terminal, I'm going into the python_test folder then I'm running python read.py then I have the following error :

Traceback (most recent call last):
  File "read.py", line 4, in <module>
    print image_to_string(Image.open('test.png'))
  File "/anaconda/anaconda/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 161, in image_to_string
    config=config)
  File "/anaconda/anaconda/lib/python2.7/site-packages/pytesseract/pytesseract.py", line 94, in run_tesseract
    stderr=subprocess.PIPE)
  File "/anaconda/anaconda/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)
  File "/anaconda/anaconda/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

我做错了什么?

推荐答案

我遇到了和你一样的错误,安装 tesseract 包修复了它(或 tesseract-ocr在 debian/ubuntu 上).它包含 pytesseract 在幕后使用的本机代码库.

I got the same error as you, installing the tesseract package fixed it (or tesseract-ocr on debian/ubuntu). It contains the native code library used under the hood by pytesseract.

如果未安装底层本机库,图像加载错误似乎是库失败的一种奇怪方式,但您去了.

An image load error seems like an odd way for the library to fail if the underlying native library is not installed, but there you go.

安装使用命令(根据需要插入 sudo)

To install use commands (insert sudo as appropriate)

马克斯

brew install tesseract

Ubuntu

apt install tesseract-ocr

这篇关于pytesseract:无法使用“Image.open"访问图像;《错误2》错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆