- 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>
34 lines
868 B
Python
34 lines
868 B
Python
"""
|
||
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)
|