如何使用PyTesseract将Python代码编译为EXE?

时间:2019-03-04 23:45:06

标签: python pyinstaller python-tesseract

我有一个使用 pytesseract 库的Python项目。 我在PyCharm中测试过。 Python版本3.7。 现在,我正在尝试使用PyInstaller将此项目编译为exe。

运行exe时出现错误:

  

文件“ getTextFromScreen.py”,第5行,位于ModuleNotFoundError中:

     

没有名为'pytesseract'的模块[9188]无法执行脚本主程序

我的导入代码如下:

import pytesseract
pytesseract.pytesseract.tesseract_cmd = r'Tesseract-OCR\tesseract'

我在python项目文件夹和已编译的项目文件夹中提供了整个“ Tesseract-OCR”文件夹。

我不知道我做错了什么。 我想向您寻求帮助

2 个答案:

答案 0 :(得分:1)

您是否正在使用Windows?您的路径中必须包含.exe扩展名。只能使用No tests were found!!!来代替r'Tesseract-OCR\tesseract'。我也有一个使用PyTesseract的项目,在python项目中提供了一个完整的tesseract文件夹,使用PyInstaller编译后效果很好。

答案 1 :(得分:0)

如果你想创建一个 .exe 并从任何其他没有 Tesseract 的电脑上运行它,你必须使用 auto-py-to-exe 工具,在附加文件选项中附加所有 Tesseract 文件所在的文件夹已安装,然后将其放入您的代码中

import sys

if getattr(sys, 'frozen', False):
    _path = os.path.join(sys._MEIPASS, './tresseract/tesseract.exe')
    print(_path)
    pytesseract.pytesseract.tesseract_cmd =_path
    # the .exe will look here
else:
    pytesseract.pytesseract.tesseract_cmd = r"C:\tresseract\\tesseract.exe"
    #ruta donde se encuentre su tresseract

并编译,祝你好运!!

相关问题