Skip to main content
 首页 » 编程设计

python之pytesser 给出导入错误

2025年04月02日14lyj

我正在尝试在 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 的文件夹 还有一个名为 PIL 的目录,它来自 PILLOW 的安装。

编辑:我在 Why can't Python import Image from PIL? 尝试了解决方案.但是好像也没什么用

请您参考如下方法:

根据回溯,错误不是来自 c:\Python27\Lib\Site-Packages 中的 pytesser,而是来自 C:\Python27\pytesser.py 第 6 行

您可以分享 C:\Python27\pytesser.py 第 6 行的代码吗?或者通过查看 C:\Python27\pytesser.py line 6

中的代码来调试它

如果你想让你的ocr.py使用位于C:\Python27\Lib\site-packages(如果存在)的pytesser,请从ocr.py目录中删除pytesser.py

如果是自己编码的话,最好是from PIL import Image,而不是import Image