首页 文章

Pytesseract TesseractNotFoundError [Python 3]

提问于
浏览
1

我使用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(最近一次调用最后一次):文件“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“,第990行,在_execute_child startupinfo中)FileNotFoundError:[WinError 2] Das System kann die angegebene Datei nicht finden在处理上述异常期间,发生了另一个异常:Traceback(最近一次)最后调用):文件“C:\ Users \ Artur \ Desktop \ Pytesseract_test.py”,第6行,在x = pytesseract.image_to_string(Image.open('frame_0000.png'))文件“C:\ Users \ Artur \应用程序数据\本地\程序\ Pyth在\ Python36 \ lib \ site-packages \ pytesseract \ pytesseract.py“,第286行,在image_to_string中返回run_and_get_output(图像,'txt',lang,config,nice)文件”C:\ Users \ Artur \ AppData \ Local \程序\ Python \ Python36 \ lib \ site-packages \ pytesseract \ pytesseract.py“,第201行,在run_and_get_output中引发TesseractNotFoundError()pytesseract.pytesseract.TesseractNotFoundError:未安装tesseract或它不在您的路径中

我正在尝试运行解决方法,但我的经验不足阻止我正确实现这一点:

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)

有人可以帮我解决这个问题吗?我没有在线提供解决方案 .

3 回答

  • 2

    发生错误的原因是代码是使用python3编译的,但模块是使用 pip 安装的 .
    所以pytesseract模块安装到Python2而不是Python3 .
    使用pip3安装可以解决问题 .

  • 3

    〜对于任何仍然遇到这个并且是初学程序员的人(因为我认为自己是一个)

    对于Mac OS

    尝试查找tesseract.exe的位置 - 如果您使用 brew 安装它,在您的终端上使用:

    >brew list tesseract
    

    这应该列出你的tesseract.exe所在的位置,或多或少的地方

    > /usr/local/Cellar/tesseract/3.05.02/bin/tesseract
    

    Then following their instructions

    pytesseract.pytesseract.tesseract_cmd = r'<full_path_to_your_tesseract_executable>'
    

    pytesseract.pytesseract.tesseract_cmd = r'/ usr / local / Cellar / tesseract / 3.05.02 / bin / tesseract'

    应该做的伎俩!

  • 2

    对于有这个问题的其他人

    我必须进入pytesseract.py文件并更改我的: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'
    没有解决问题

相关问题