python - tesseract.exe 未安装或不在您的路径中

标签 python python-tesseract

我正在使用 Pytesseract 来读取 PDF 的特定部分。以下是将 tesseract 配置到我的代码中的代码。

pytesseract.pytesseract.tesseract_cmd = os.path.join(cwd, "Tesseract-OCR\\tesseract.exe")

cwd 与我的 SplitPDF.py 文件和 Tesseract-OCR(包含 tesseract.exe)文件夹所在的目录相同。

当我执行 SplitPDF.py 时,一切正常,并且我得到了所需的输出。 但是当我创建 SplitPDF.exe (使用 Pyinstaller)时出现问题,我收到一条错误消息,指出 tesseract.exe 未安装或不在您的路径中。

以下是完整的错误:

Traceback (most recent call last): File "site-packages\pytesseract\pytesseract.py", line 223, in run_tesseract File "subprocess.py", line 775, in init File "subprocess.py", line 1178, in _execute_child 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 "tkinter__init__.py", line 1705, in call File "PDF_Splitter.py", line 241, in UploadAction1 pdfsplitbylca(entryString) File "Split_by_LCA_1.py", line 155, in pdfsplitbylca text = pytesseract.image_to_string(im, lang = 'eng') File "site-packages\pytesseract\pytesseract.py", line 345, in image_to_string File "site-packages\pytesseract\pytesseract.py", line 344, in File "site-packages\pytesseract\pytesseract.py", line 253, in run_and_get_output File "site-packages\pytesseract\pytesseract.py", line 225, in run_tesseract pytesseract.pytesseract.TesseractNotFoundError: C:\Users\VADIRA~1.KAT\AppData\Local\Temp_MEI370202\Tesseract-OCR\tesseract.exe is not installed or it's not in your path

我是否没有正确创建 .exe 或者是否有更好的方法来配置 Tesseract?

最佳答案

您应该考虑使用 Pytesseract 库(tesseract python 库)而不是可执行文件。我希望这有帮助。使用方法非常简单。您必须先安装它,然后才能使用

import pytesseract
from PIL import Image

pytesseract.image_to_string(Image.open('image'))

希望这有帮助

关于python - tesseract.exe 未安装或不在您的路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59378317/

相关文章:

python - 获取每组 pandas 的前 n 行

c++ - Boost::Python raw_function 返回 void

python - 你如何通过将它与单独的列表进行比较来对 python 中的列表进行排序?

python - Mongodb 我可以构造这些数据吗

python - 超正方体 OCR : Parameter for Font Size (Single Character)

opencv - OpenCV Python中OCR的90度斜度校正

python - 如果您知道使用 pandas 数据框的列值和行值,如何检索数据?

python - pytesseract 努力识别带有字体编号和 7 段数字的干净黑白图片(python)

python - 如何将图像中的标题和标题与正文分开

python - 错误 5 :Access denied PyTesseract