繁体   English   中英

cx_Freeze:在其他PC上使用pytesseract可执行文件失败

[英]cx_Freeze: Executable with pytesseract fails on other PC

我已经使用cx_Freeze从我的Python-OCR程序( import pytesseract )中创建了一个可执行文件。 生成的.exe在我自己的计算机上可以正常工作。 为了测试该程序,我制作了一个zip文件夹,并在共享点上与一些朋友和同事共享。 现在,可执行文件存在以下问题。 似乎pytesseract没有包含在可执行文件/ zip文件夹中。

这是ErrorLog:

The file is not a PNG-file:  20181108 Kontaktanzeigen-Er_sucht_sie.jpg
The file is not a PNG-file:  20181108 Kontaktanzeigen-Sie_sucht_ihn.jpg
The file is not a PNG-file:  20181108 Language family tree.jpg
The file is not a PNG-file:  20181108 relax.jpg
The file is not a PNG-file:  20181109 Essen wie Gott am Südpol S1.JPG
The file is not a PNG-file:  20181109 Fahrzeugschein1.jpg
The file is not a PNG-file:  20181112 sie_sind_alle_so_dumm.jpg
Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 170, in run_tesseract
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\subprocess.py", line 707, in __init__
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\subprocess.py", line 992, in _execute_child
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:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\threading.py", line 916, in _bootstrap_inner
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\threading.py", line 864, in run
  File "C:\Users\TFischer\PycharmProjects\Test_Project\OCR.py", line 67, in img_to_text
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 294, in image_to_string
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 202, in run_and_get_output
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 172, in run_tesseract
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 170, in run_tesseract
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\subprocess.py", line 707, in __init__
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\subprocess.py", line 992, in _execute_child
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:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\threading.py", line 916, in _bootstrap_inner
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\threading.py", line 864, in run
  File "C:\Users\TFischer\PycharmProjects\Test_Project\OCR.py", line 73, in img_to_text1
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 294, in image_to_string
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 202, in run_and_get_output
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\pytesseract\pytesseract.py", line 172, in run_tesseract
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your path

第一行是绝对清楚的。 我发现了一些修改setup.py想法,以将所有导入内容包含在cx_Freeze创建的可执行文件中。 这是最新版本。

from cx_Freeze import setup, Executable
import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

additional_mods = ['numpy.core._methods', 'numpy.lib.format']
additional_files = [os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
            os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')]

options = {
    'build_exe': {'include_files': additional_files, 'includes': additional_mods}
    }

setup(options = options,
      name = "main" ,
      version = "0.1" ,
      description = "" ,
      executables = [Executable("main.py")])

pytesseract是Google Tesseract-OCR引擎的包装。 为了使pytesseract正常工作,需要安装Tesseract-OCR引擎,并且必须能够将tesseract命令作为tesseract调用(这意味着Tesseract-OCR安装目录必须位于PATH中)。

我相信pytesseract已正确包含在可执行文件中,但tesseract命令在“另一台PC”上不起作用(要么Tesseract-OCR未安装在该目录中,要么Tesseract-OCR安装目录不在该路径中)。

您需要告诉“另一台PC”的所有者安装Tesseract-OCR,并检查是否可以从任何位置使用tesseract命令启动它。

另一种选择是使用包括在冷冻可执行整个的Tesseract-OCR安装目录build_exe选项include_files (你的变量additional_files ),并确保此列入目录被包含在目标计算机上的路径,但是这可能不是与平台无关,因此不建议使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM