fix: 解决打包后三个运行时问题

- rthook_paddle.py: stub paddle.utils.cpp_extension,避免Cython缺文件崩溃
- build_exe.py: 显式收集paddle DLLs(mklml.dll等)
- ocr_offline.py: 非ASCII路径自动复制模型到临时目录,绕过PaddlePaddle C++路径限制

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
let5sne.win10
2026-02-14 20:31:28 +08:00
parent dfbab1b61e
commit 86cb704eae
3 changed files with 78 additions and 2 deletions

33
rthook_paddle.py Normal file
View File

@@ -0,0 +1,33 @@
"""
PyInstaller runtime hook: stub 掉 paddle 中仅开发时需要的模块,
避免打包后因缺少 Cython Utility 文件而崩溃。
"""
import types
import sys
class _Stub(types.ModuleType):
"""空模块 stub所有属性访问返回空类"""
def __getattr__(self, name):
if name.startswith("_"):
raise AttributeError(name)
return type(name, (), {})
def _inject(name):
if name not in sys.modules:
m = _Stub(name)
m.__path__ = []
m.__package__ = name
m.__spec__ = None
sys.modules[name] = m
# paddle.utils.cpp_extension 会拉入 Cython 编译器,推理不需要
for _p in [
"paddle.utils.cpp_extension",
"paddle.utils.cpp_extension.cpp_extension",
"paddle.utils.cpp_extension.extension_utils",
"paddle.utils.cpp_extension.jit_compile",
]:
_inject(_p)