注:PADDLEOCR_PATH设置的是path的包路径;CODE_PATH设置的是代码的主文件(main.py)的路径。
执行打包命令
(1) 带有调试窗口
pyinstaller --clean -y -D --clean -p %PADDLEOCR_PATH%\paddle\libs;%PADDLEOCR_PATH%\paddleocr;%PADDLEOCR_PATH%\paddleocr\ppocr\utils\e2e_utils;%PADDLEOCR_PATH%\paddleocr\ppstructure\table main.py -i ocr.ico --add-binary %PADDLEOCR_PATH%\paddle\libs;. --add-data %CODE_PATH%\ocr.ico;. --add-data %PADDLEOCR_PATH%\paddleocr\ppocr\utils\ppocr_keys_v1.txt;.\ppocr\utils --add-data %PADDLEOCR_PATH%\paddleocr\ppocr\utils\dict\table_structure_dict.txt;.\ppocr\utils\dict --add-data %PADDLEOCR_PATH%\layoutparser\misc\NotoSerifCJKjp-Regular.otf;.\layoutparser\misc --additional-hooks-dir=. --hidden-import extract_textpoint_slow --hidden-import tablepyxl --hidden-import tablepyxl.style
(2) 不带调试窗口
pyinstaller --clean -y -D -w --clean -p %PADDLEOCR_PATH%\paddle\libs;%PADDLEOCR_PATH%\paddleocr;%PADDLEOCR_PATH%\paddleocr\ppocr\utils\e2e_utils;%PADDLEOCR_PATH%\paddleocr\ppstructure\table main.py -i ocr.ico --add-binary %PADDLEOCR_PATH%\paddle\libs;. --add-data %CODE_PATH%\ocr.ico;. --add-data %PADDLEOCR_PATH%\paddleocr\ppocr\utils\ppocr_keys_v1.txt;.\ppocr\utils --add-data %PADDLEOCR_PATH%\paddleocr\ppocr\utils\dict\table_structure_dict.txt;.\ppocr\utils\dict --add-data %PADDLEOCR_PATH%\layoutparser\misc\NotoSerifCJKjp-Regular.otf;.\layoutparser\misc --additional-hooks-dir=. --hidden-import extract_textpoint_slow --hidden-import tablepyxl --hidden-import tablepyxl.style
可执行程序会生成在CODE_PATH\dist\main下面报错
解决办法,把python安装目录下的python.exe拷贝到和当前编译好的exe同一个目录
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “main.py”, line 7, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “UIModule\MainWidgetHandle.py”, line 15, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “Algorithm\OcrIdentify.py”, line 6, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddleocr.py”, line 20, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle_init_.py”, line 45, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\distributed_init_.py”, line 15, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\distributed\spawn.py”, line 24, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\distributed\utils.py”, line 28, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\distributed\fleet_init_.py”, line 20, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\distributed\fleet\base\fleet_base.py”, line 31, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\fluid\ir.py”, line 27, in
File “PyInstaller\loader\pyimod03_importers.py”, line 495, in exec_module
File “paddle\fluid\proto\pass_desc_pb2.py”, line 16, in
ModuleNotFoundError: No module named ‘framework_pb2’
解决办法,把paddleocr安装目录下的proto文件夹,直接拷贝到CODE_PATH\dist\main\paddle\fluid下面