You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyInstaller显式添加hidden import仍找不到gino-starlette该如何调试

问题原因

Gino 采用了动态别名机制加载扩展,你代码中用到的gino.ext.starlette是虚拟导入路径,实际对应安装的gino_starlette模块。你之前仅添加了gino_starlette和gino.ext的隐藏导入,PyInstaller 无法识别gino.ext.starlette这个虚拟路径和实际模块的关联关系,因此 Gino 内部的动态查找逻辑会抛出找不到扩展的错误。

解决步骤
  • 第一步:先尝试补全隐藏导入重打包,将打包命令修改为:
    pyinstaller --hidden-import gino_starlette --hidden-import gino.ext --hidden-import gino.ext.starlette --noconfirm windows_runner.py --clean
    如果运行仍然报错,继续执行下一步。

  • 第二步:添加自定义 PyInstaller 钩子处理动态导入
    在打包目录下新建名为hook-gino.ext.py的文件,写入以下内容:

from PyInstaller.utils.hooks import collect_submodules

hiddenimports = collect_submodules('gino.ext') + [
    "gino_starlette",
    "gino.ext.starlette"
]

打包时新增参数指定钩子目录:
pyinstaller --hidden-import gino_starlette --hidden-import gino.ext --hidden-import gino.ext.starlette --additional-hooks-dir=. --noconfirm windows_runner.py --clean

  • 第三步:强制模块别名映射(终极方案)
    如果以上方案都无效,直接在入口文件windows_runner.py的最开头添加以下代码,手动把虚拟路径和实际模块做绑定,绕开 Gino 的动态查找逻辑:
import gino_starlette
import sys
sys.modules["gino.ext.starlette"] = gino_starlette

之后再正常打包即可。

调试技巧
  • 打包时添加--log-level DEBUG参数,可以在打包日志中确认gino.ext.starlette和gino_starlette是否被正确加入导入列表
  • 运行生成的可执行文件时添加--debug imports参数,可以打印完整的导入流程日志,定位缺失的模块

内容的提问来源于stack exchange,提问作者Yash Mandhyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 06:45:03