我已使用
安装了pytesseract
库
pip install pytesseract
当我尝试使用image_to_text
方法时,它给了我一个
FileNotFoundError:[WinError 2]系统找不到指定的文件
我用谷歌搜索它,发现我应该在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,'用法: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')
答案 0 :(得分:3)
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环境变量中,或使用{{1}声明它的位置属性
答案 1 :(得分:1)
对于与我情况相同的人:here是tesseract-OCR下载程序。完成下载后,转到您选择的路径,应该有一个名为tesseract.exe
的文件,复制此文件的路径并将其粘贴到pytesseract.exe
。
答案 2 :(得分:0)