我在使用 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'))
错误发生在最后一行。 (x = ...)
结果:
Traceback (most recent call last): File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 194, in run_and_get_output run_tesseract(**kwargs) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 165, in run_tesseract proc = subprocess.Popen(command, **subprocess_args()) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 707, in init restore_signals, start_new_session) File "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
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Artur\Desktop\Pytesseract_test.py", line 6, in x = pytesseract.image_to_string(Image.open('frame_0000.png')) File "C:\Users\Artur\AppData\Local\Programs\Python\Python36\lib\site-packages\pytesseract\pytesseract.py", line 286, in 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 not in your path
我正在尝试运行一个解决方法,但我的经验不足使我无法正确实现:
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)
有人可以帮我解决这个问题吗?我无法使用在线提供的解决方案。
最佳答案
对于遇到此问题的其他人
I had to go into the pytesseract.py file and changed my:
tesseract_cmd = 'tesseract'
To:
tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
免责声明:做
pytesseract.tesseract_cmd = '/usr/local/Cellar/tesseract/3.05.02/bin/tesseract'
没有解决问题
关于python - Pytesseract TesseractNotFoundError [Python 3],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51154729/