Skip to main content
 首页 » 编程设计

python之为什么 pytesseract 抛出 WinError 6

2025年02月15日8JustinYoung

这是我第一次使用 pytesseract。我正在尝试对小图像执行简单的 OCR。代码归结为:

from PIL import Image 
from pytesseract import image_to_string 
 
test = Image.open(r'C:\test.jpg') 
print(image_to_string(test)) 

抛出 OSError: [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。

提前感谢您的宝贵时间!

请您参考如下方法:

我不知道真正的问题,但在我重新启动 PC 后问题就解决了。