我想完成看似简单的任务,即运行一个使用 OCR 为我提供图像中的文本字符串的 python 脚本。我的代码:
from PIL import Image
from pytesseract import *
image_file = 'IMG_9296'
im = Image.open(image_file)
text = image_to_string(im)
text = image_file_to_string(image_file)
text = image_file_to_string(image_file, graceful_errors=True)
print "=====output=======\n"
print text
但是,我在第二行遇到了麻烦。我在我的 Mac OS X 上成功安装了枕头、PIL 和 pytesseract(运行 Python 2.7、Pillow-5.0.0 pytesseract-0.2.0)。但我收到了这个错误:
Traceback (most recent call last):
File "./HQcode2.py", line 2, in <module>
from pytesseract import *
File "/Library/Python/2.7/site-packages/pytesseract/__init__.py", line
1, in <module>
from .pytesseract import (
File "/Library/Python/2.7/site-packages/pytesseract/pytesseract.py",
line 9, in <module>
import Image
File "/Library/Python/2.7/site-packages/PIL/Image.py", line 27, in
<module>
from . import VERSION, PILLOW_VERSION, _plugins
ValueError: Attempted relative import in non-package
我已经查看了这个错误,但还没有发现任何对我的案例有帮助的东西。这里似乎有什么问题,我该如何解决?