首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在以前工作正常的代码上收到"pytesseract not in your path“错误

在以前工作正常的代码上收到"pytesseract not in your path“错误
EN

Stack Overflow用户
提问于 2019-04-09 06:14:11
回答 1查看 981关注 0票数 2

我在几个月前编写了这段代码,希望通过它来清理它并添加一些新功能。这是一个简单的工具,我用来给我的屏幕拍照,并从中获取可写的单词。我在一台新的计算机上,而不是我最初编写代码的那台计算机上;但是,我通过pycharm模块管理器检查并安装了每个模块。然而,当我运行代码时,即使我在path中找到了这个包,我仍然得到这个错误。任何帮助都将不胜感激。

我已经查找了我的问题的几个不同的变体,但它们似乎都有不同的原因和解决方法,当然,没有一个对我有效。

代码语言:javascript
复制
    if c ==2:
        img = ImageGrab.grab(bbox=(x1-5, y1-5, x2+5,y2+5))  # bbox specifies region (bbox= x,y,width,height)
        img_np = np.array(img)
        frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
        c = 0
        x = 0
        string = str(pytesseract.image_to_string(frame)).lower()
        print(string)

这是代码中唯一引用pytesseract的部分,当然不是"import pytesseract“。希望我能重新启动并运行这段代码和pytesseract模块,因为它是我的许多脚本中不可或缺的部分。提前感谢您的帮助。

代码语言:javascript
复制
  File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 184, in run_tesseract
    proc = subprocess.Popen(cmd_args, **subprocess_args())
  File "C:\Users\dante\Anaconda3\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\dante\Anaconda3\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/dante/Desktop/DPC/processes/screen_to_text.py", line 29, in <module>
    string = str(pytesseract.image_to_string(frame)).lower()
  File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 309, in image_to_string
    }[output_type]()
  File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 308, in <lambda>
    Output.STRING: lambda: run_and_get_output(*args),
  File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 218, in run_and_get_output
    run_tesseract(**kwargs)
  File "C:\Users\dante\Anaconda3\lib\site-packages\pytesseract\pytesseract.py", line 186, in run_tesseract
    raise TesseractNotFoundError()
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path```
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-11 10:58:16

问题出在我对这个模块缺乏理解。pytesseract不是一个OCR,它只是一个允许用户使用googles的翻译器。这意味着,为了使用这个软件包,用户必须安装谷歌的OCR (我从这里的https://sourceforge.net/projects/tesseract-ocr-alt/files/下载了我的)。

这不会;但是,解决了全部问题。pytesseract包需要知道实际OCR程序的位置。在pytesseract.py脚本的第35行,有一行告诉pytesseract在哪里可以找到实际的google OCR tesseract程序

代码语言:javascript
复制
tesseract_cmd = 'tesseract'

如果你使用的是windows,并且你还没有手动将tesseract添加到你的路径中(如果你不知道这意味着什么,请按照下面的步骤操作),那么你需要用google OCR在你电脑上的实际位置来替换该行。将该行替换为

代码语言:javascript
复制
tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract'

应该允许你运行pytesseract,假设你已经正确地安装了所有东西。我花了比我愿意承认的更长的时间来找到这个问题的明显解决方案,但希望将来有这个问题的人能比我更快地解决它!谢谢,祝你有愉快的一天。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55582511

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档