Why is pyinstaller not analyzing hidden import 'paddle.fluid.proto.framework_pb2'

537 Views Asked by At

I have a python script that uses paddleOCR which runs fine.

Using pyinstaller, the exe is generate successfully but when the exe is run, it generates this error:

Traceback (most recent call last):
  File "mri_ocr_core.py", line 1, in <module>
  File "connect_backend_core.py", line 12, in init connect_backend_core
  File "main_core.py", line 17, in init main_core
  File "ocr2.py", line 35, in init ocr2
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddleocr\__init__.py", line 14, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddleocr\paddleocr.py", line 21, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\__init__.py", line 57, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\__init__.py", line 15, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\spawn.py", line 24, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\utils.py", line 28, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\__init__.py", line 20, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\base\fleet_base.py", line 31, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\ir.py", line 28, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'
[31068] Failed to execute script 'mri_ocr_core' due to unhandled exception!

Python 3.7.9
paddle-bfloat==0.1.7
paddleocr==2.6.0.1
paddlepaddle==2.3.2
pyinstaller==5.6.2
pyinstaller-hooks-contrib==2022.2

With paddle.fluid.proto.framework_pb2 added to hiddenimports, when pyinstaller is run the generated debug messages don't show that pyinstaller analyzes hidden import 'paddle.fluid.proto.framework_pb2'.

EDIT: To reproduce this issue

  1. Install Python 3.7.9
  2. Install the CPU version of paddlepaddle with:
python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
  1. Install the latest paddleOCR
pip install "paddleocr>=2.6.0.3"
  1. Install pyinstaller
pip install pyinstaller
  1. Create the following script file (test.py)
from paddleocr import PaddleOCR,draw_ocr
img_path = r'./66.png'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line)
  1. Build exe using pyinstaller
pyinstaller test.py --noconfirm
  1. Running the generated test.exe results in the following error
Traceback (most recent call last):
  File "paddle\fluid\ir.py", line 24, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddleocr\__init__.py", line 14, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddleocr\paddleocr.py", line 21, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\__init__.py", line 62, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\__init__.py", line 15, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\spawn.py", line 24, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\utils\launch_utils.py", line 27, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\__init__.py", line 31, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\distributed\fleet\fleet.py", line 33, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\ir.py", line 28, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
  File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'
[15880] Failed to execute script 'test' due to unhandled exception!
  1. Modify this section of the test.spec file to extend hiddenimports with paddle.fluid.proto.framework_pb2
hiddenimports = set()
hiddenimports = list(hiddenimports)
hiddenimports.extend(['paddle.fluid.proto.framework_pb2'])

a = Analysis(
    ['test.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=hiddenimports,
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)

  1. Run pyinstaller again using the spec file
pyinstaller test.spec --noconfirm
  1. In the output, paddle.fluid.proto.framework_pb2 is not analyzed.
0

There are 0 best solutions below