2016-08-13 116 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' –