我正在尝试用python实现OCR。当我运行以下代码时:
from PIL import Image
from pytesser import *
image_file = 'menu.jpg'
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我得到以下错误:
Traceback (most recent call last):
File "C:/Python27/ocr.py", line 2, in <module>
from pytesser import *
File "C:/Python27\pytesser.py", line 6, in <module>
ImportError: No module named Image我在我的C:\Python27\Lib\site-packages目录中有一个名为pytesser的文件夹,在安装PILLOW的同一目录中还有一个名为PIL的文件夹。
编辑:我在Why can't Python import Image from PIL?上尝试了这个解决方案。但这似乎没什么帮助
发布于 2016-08-13 13:15:22
根据回溯,错误不是来自c:\Python27\Lib\Site-Packages中的pytesser,而是来自C:\Python27\pytesser.py line 6
你能分享一下C:\Python27\pytesser.py第6行的代码吗?或者通过查看C:\Python27\pytesser.py line 6上的代码来调试它
如果您希望ocr.py使用C:\Python27\Lib\site-packages中的pytesser (如果存在),请从ocr.py目录中删除pytesser
如果它是您自己编写的,理想情况下应该是from PIL import Image,而不是import Image
https://stackoverflow.com/questions/38929372
复制相似问题