2016-08-13 118 views
2

我想在Python中实现OCR。当我运行下面的代码:pytesser给出导入错误

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 并在其中来自同一个目录中名为PIL PILLOW的安装。编号:Why can't Python import Image from PIL?我试过解决方案。但它似乎并没有帮助

+1

的可能的复制[为什么可以从PIL不能Python的导入图像?](http://stackoverflow.com/questions/ 26505958/why-cant-python-import-image-from-pil) – Karin

+0

谢谢。我尝试了那里提到的方法。但它没有帮助。我猜pytesser与PIL整合有问题。但不知道。 –

回答

1

按回溯,错误不是从c:\Python27\Lib\Site-Packagespytesser,它是从C:\Python27\pytesser.py line 6

未来你位于C共享代码:\ Python27 \ pytesser.py线6 ?或者调试它通过在C:\Python27\pytesser.py line 6

看代码如果你希望你的ocr.py在C使用pytesser:\ Python27 \ LIB \站点包(如果存在的话),请从OCR的目录中删除pytesser.py的.py

如果是由你的编码,理想应该是from PIL import Image,不import Image

+0

我试着在'C:\ Python27 \ pytesser.py'中打开'pytesser.py'文件。它是一个编译的Python文件,并在打开时显示相同的错误。 –

+0

你的意思是你不能打开它? –

+0

我双击它,python命令行闪烁并读取相同的错误'ImportError:No module Name Image' –