2017-01-11 9 views
2

これは初めてpytesseractを使用しています。私は小さな画像で簡単なOCRを実行しようとしています。これはOSErrorのをスローpytesseractがWinError 6を投げているのはなぜですか?

from PIL import Image 
from pytesseract import image_to_string 

test = Image.open(r'C:\test.jpg') 
print(image_to_string(test)) 

:コードはつまるところ[WinError 6]ハンドルは

Traceback (most recent call last): 
    File "C:\Testing.py", line 5, in <module> 
    print(image_to_string(test)) 
    File "C:\\pytesseract.py", line 161, in image_to_string 
    config=config) 
    File "C:\\pytesseract.py", line 94, in run_tesseract 
    stderr=subprocess.PIPE) 
    File "C:\\subprocess.py", line 911, in __init__ 
    errread, errwrite) = self._get_handles(stdin, stdout, stderr) 
    File "C:\\subprocess.py", line 1150, in _get_handles 
    c2pwrite = self._make_inheritable(c2pwrite) 
    File "C:\\subprocess.py", line 1182, in _make_inheritable 
    _winapi.DUPLICATE_SAME_ACCESS) 
OSError: [WinError 6] The handle is invalid 

無効である私は、Windows 7上で事前に

おかげでPythonの3.5を使用していますあなたの時間!

答えて

0

私は、だから私はすべての様々なファイルをトラブルシューティングするにはPythonについて十分に知らないが、私は問題はサブプロセスファイルによるものであった私のための通知をした...同じ問題がありました。どうやらpytesseractがサブプロセスを呼び出すと、スクリプトはエラーを投げます。いずれの場合においても

は、私は完全にpytesseractをスキップし、サブプロセスを経由してたTesseractにアクセスすることで問題を回避しました。私のコードは以下の通りです:

import subprocess 
from subprocess import Popen, PIPE 
image_file = r"C:\Temp\test.png" 
outlocation = r"C:\Temp\output" 
command = ['tesseract', image_file, outlocation] 
proc = subprocess.Popen(command, 
     stderr=subprocess.PIPE) 

これは非常にバンド補助ソリューションですが、私はPythonでtesseractの使用を進めることができました。それが役に立てば幸い。

また、上記の回避策は、すでにたTesseractがインストールされている前提としています。そうでない場合は、あなたは私が本当の問題を知らないhttps://github.com/UB-Mannheim/tesseract/wiki

1

からそれをつかむことができますが、私はPCを再起動したら、問題が解決しました。

+1

それが直接私がコメントする権利を持っていない「答え」質問 –

+0

を助けていないので、これはコメントに、より適しているだろう。将来があれば気をつけます..ありがとう。 – Abdul

関連する問題