我在使用 pytesseract 时遇到错误。我是通过 pip install 安装的。
代码:
import pytesseract
from PIL import Image
img = Image.open('frame_0000.png')
x = pytesseract.image_to_string(Image.open('frame_0000.png'))
Run Code Online (Sandbox Code Playgroud)
错误发生在最后一行。(x = ...)
结果:
回溯(最近一次调用):文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py”,第 194 行,在 run_and_get_output run_tesseract(**kwargs ) 文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py”,第 165 行,在 run_tesseract proc = subprocess.Popen(command, **subprocess_args( )) 文件“C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py”,第 707 行,在init restore_signals, start_new_session 中)文件“C:\Users\Artur\AppData\Local\ Programs\Python\Python36\lib\subprocess.py", line 990, in _execute_child startupinfo) FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden
在处理上述异常的过程中,又发生了一个异常:
回溯(最近一次调用):文件“C:\Users\Artur\Desktop\Pytesseract_test.py”,第 6 行,在 x = pytesseract.image_to_string(Image.open('frame_0000.png')) 文件“C:\ Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py”,第 286 行,在 image_to_string 中 return run_and_get_output(image, 'txt', lang, config, nice) File "C :\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 201, in run_and_get_output raise TesseractNotFoundError() pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's不在你的路上
我正在尝试运行解决方法,但我的经验不足使我无法正确执行此操作:
tessdata_dir_config = '--tessdata-dir "<replace_with_your_tessdata_dir_path>"'
# Example config: '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
# It's important to include double quotes around the dir path.
pytesseract.image_to_string(image, lang='chi_sim', config=tessdata_dir_config)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?我没有得到在线提供的解决方案来工作。
我不得不进入 pytesseract.py 文件并将我的:改为
tesseract_cmd = 'tesseract'
:
tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
免责声明:这样做
pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
并没有解决问题