简体   繁体   English

OSError: [WinError 193] %1 不是有效的 Win32 应用程序 Python

[英]OSError: [WinError 193] %1 is not a valid Win32 application Python

i'm trying to setup a simple OCR with python, I'm now doing tests.我正在尝试使用 python 设置一个简单的 OCR,我现在正在做测试。 I use notepad++, Python 3.10.1, PIP, Pillow, pytesseract.我使用记事本++、Python 3.10.1、PIP、Pillow、pytesseract。 This is my code :这是我的代码:

import pytesseract
import numpy 
from PIL import Image, ImageEnhance, ImageFilter

pytesseract.pytesseract.tesseract_cmd = 'Lib/site-packages/pytesseract/pytesseract.py'
im = Image.open(r"C:\Users\Leonid\AppData\Local\Programs\Python\Python310\Lib\site-packages\pytesseract\test.jpg") # Ouverture du fichier image

# Filtrage (augmentation du contraste)
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')

# Lancement de la procédure de reconnaissance
text = pytesseract.image_to_string(im)
print(text)

When I execute the code, i get this error :当我执行代码时,我得到这个错误:

Traceback (most recent call last):
  File "C:\Users\Leonid\Desktop\Python\test.py", line 15, in <module>
    text = pytesseract.image_to_string(im)
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 416, in image_to_string
    return {
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 419, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 286, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 257, in run_tesseract
    raise e
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\site-packages\pytesseract\pytesseract.py", line 254, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Leonid\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 n’est pas une application Win32 valide

I tried to install numpy cause i've seen on forums that it solves the problem, and import it ("Import numpy" , line 2).我尝试安装 numpy 因为我在论坛上看到它解决了问题,然后将其导入(“Import numpy”,第 2 行)。 But it still don't work.但它仍然不起作用。

What can cause this error and how to fix it?什么可能导致此错误以及如何解决?

The problem is this line:问题是这一行:

pytesseract.pytesseract.tesseract_cmd = 'Lib/site-packages/pytesseract/pytesseract.py'

You need to set pytesseract.pytesseract.tesseract_cmd to the location of the Tesseract executable.您需要将pytesseract.pytesseract.tesseract_cmd设置为 Tesseract 可执行文件的位置。 You have instead set it to some Python script.您已将其设置为一些 Python 脚本。

See this question for some examples of what this should be set to.有关应设置的内容的一些示例,请参阅此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OSError: [WinError 193] %1 不是 Python 中的有效 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application in python OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - python - OSError: [WinError 193] %1 is not a valid Win32 application - python Python 错误:OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - Python error: OSError: [WinError 193] %1 is not a valid Win32 application OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application OSError: [WinError 193] %1 不是有效的 Win32 应用程序 (Pandas) - OSError: [WinError 193] %1 is not a valid Win32 application (Pandas) OSError: [WinError 193] %1 不是 CTypes 中的有效 Win32 应用程序 - OSError: [WinError 193] %1 is not a valid Win32 application in CTypes OSError: [WinError 193] %1 不是有效的 Win32 应用程序 - nltk - OSError: [WinError 193] %1 is not a valid Win32 application - nltk OSError: [WinError 193] %1 不是有效的 Win32 应用程序 (LibTiff) - OSError: [WinError 193] %1 is not a valid Win32 application (LibTiff) 如何修复“OSError: [WinError 193] %1 不是有效的 Win32 应用程序” - How to fix"OSError: [WinError 193] %1 is not a valid Win32 application" Azure - numpy - OSError:[WinError 193]%1不是有效的Win32应用程序 - Azure - numpy - OSError: [WinError 193] %1 is not a valid Win32 application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM