gpt4 book ai didi

python - 文件 tesseract.exe 不存在

转载 作者:太空宇宙 更新时间:2023-11-04 09:58:37 27 4
gpt4 key购买 nike

我已经使用

安装了 pytesseract
pip install pytesseract

当我尝试使用 image_to_text 方法时,它给了我一个

FileNotFoundError: [WinError 2] The system can not find the file specified

我用谷歌搜索了一下,发现我应该更改 pytesseract.py 文件和行中的某些内容

tesseract_cmd = 'tesseract'

应该变成

tesseract_cmd = path_to_folder_that_contains_tesseractEXE + 'tesseract'  

我搜索并没有在我的 Python 文件夹中找到任何 tesseract.exe 文件,然后我重新安装了该库,但该文件仍然不存在。最后,我将这一行替换为:

tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + 'pytesseract'

我的程序抛出了:

pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')

我该怎么做才能使我的程序运行?

P.S 这是我的程序代码:

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

im = Image.open(r'C:\Users\Филипп\Desktop\ImageToText_Python\NoName.png')
print(im)

txt = image_to_string(im)
print(txt)

第一次尝试的完整回溯:

File "C:/Users/user/Desktop/ImageToText.py", line 10, in <module>
text = pytesseract.image_to_string(im)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 122, in
image_to_string config=config)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 46, in
run_tesseract proc = subprocess.Popen(command, stderr=subprocess.PIPE)
File "C:\Python\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session)
File "C:\Python\lib\subprocess.py", line 1224, in _execute_child startupinfo)
FileNotFoundError: [WinError 2]The system can not find the file specified

第二次尝试的完整回溯

Traceback (most recent call last):
File "C:\Users\user\Desktop\ImageToText.py", line 6, in <module> txt = image_to_string(im)
File "C:\Python\lib\site-packages\pytesseract\pytesseract.py", line 125, in image_to_string
raise TesseractError(status, errors)
pytesseract.pytesseract.TesseractError: (2, 'Usage: python pytesseract.py [-l lang] input_file')

最佳答案

来自 project's README :

try:
import Image
except ImportError:
from PIL import Image
import pytesseract

pytesseract.pytesseract.tesseract_cmd = '<full_path_to_your_tesseract_executable>'
# Include the above line, if you don't have tesseract executable in your PATH
# Example tesseract_cmd: 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

print(pytesseract.image_to_string(Image.open('test.png')))
print(pytesseract.image_to_string(Image.open('test-european.jpg'), lang='fra'))

因此,您必须确保 tesseract.exe 在您的计算机上(例如通过安装 Tesseract-OCR),然后将包含的文件夹添加到您的 PATH 环境变量,或使用 pytesseract.pytesseract 声明它的位置。 tesseract_cmd 属性

关于python - 文件 tesseract.exe 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44821838/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com