我已经pytesseract使用安装了该库
pip install pytesseract\nRun Code Online (Sandbox Code Playgroud)\n\n当我尝试使用该image_to_text方法时,它给了我一个
\n\n\nFileNotFoundError: [WinError 2] 系统找不到指定的文件
\n
我用谷歌搜索了一下,发现我应该更改 pytesseract.py 文件和行中的某些内容
\n\ntesseract_cmd = \'tesseract\'\nRun Code Online (Sandbox Code Playgroud)\n\n应该成为
\n\ntesseract_cmd = path_to_folder_that_contains_tesseractEXE + \'tesseract\' \nRun Code Online (Sandbox Code Playgroud)\n\n我搜索并没有tesseract.exe在我的 Python 文件夹中找到任何文件,然后我重新安装了该库,但该文件仍然不存在。最后,我将该行替换为:
tesseract_cmd = path_to_folder_that_contains_pytesseractEXE + \'pytesseract\'\nRun Code Online (Sandbox Code Playgroud)\n\n我的程序抛出:
\n\n\n\n\npytesseract.pytesseract.TesseractError: (2, \'用法: python pytesseract.py [-l lang] input_file\')
\n
我该怎么做才能让我的程序正常运行?
\n\nPS这是我的程序代码:
\n\nfrom pytesseract import image_to_string\nfrom PIL import Image, ImageEnhance, ImageFilter\n\nim = Image.open(r\'C:\\Users\\\xd0\xa4\xd0\xb8\xd0\xbb\xd0\xb8\xd0\xbf\xd0\xbf\\Desktop\\ImageToText_Python\\NoName.png\') \nprint(im)\n\ntxt = image_to_string(im)\nprint(txt)\nRun Code Online (Sandbox Code Playgroud)\n\n第一次尝试的完整回溯:
\n\nFile "C:/Users/user/Desktop/ImageToText.py", line 10, in <module>\ntext = pytesseract.image_to_string(im)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 122, in \nimage_to_string config=config)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 46, in \nrun_tesseract proc = subprocess.Popen(command, stderr=subprocess.PIPE)\nFile "C:\\Python\\lib\\subprocess.py", line 947, in __init__ restore_signals, start_new_session)\nFile "C:\\Python\\lib\\subprocess.py", line 1224, in _execute_child startupinfo)\nFileNotFoundError: [WinError 2]The system can not find the file specified\nRun Code Online (Sandbox Code Playgroud)\n\n第二次尝试的完整回溯
\n\nTraceback (most recent call last):\nFile "C:\\Users\\user\\Desktop\\ImageToText.py", line 6, in <module> txt = image_to_string(im)\nFile "C:\\Python\\lib\\site-packages\\pytesseract\\pytesseract.py", line 125, in image_to_string\nraise TesseractError(status, errors)\npytesseract.pytesseract.TesseractError: (2, \'Usage: python pytesseract.py [-l lang] input_file\')\nRun Code Online (Sandbox Code Playgroud)\n
来自项目的自述文件:
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'))
Run Code Online (Sandbox Code Playgroud)
因此,您必须确保 tesseract.exe 在您的计算机上(例如通过安装 Tesseract-OCR),然后将包含的文件夹添加到您的 PATH 环境变量中,或者使用pytesseract.pytesseract.tesseract_cmd属性声明它的位置
| 归档时间: |
|
| 查看次数: |
21060 次 |
| 最近记录: |