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

Python转exe遇Hydra报错:找不到hydra._internal.core_plugins模块

解决方案

1. 手动添加Hydra内部模块到打包包含项

PyInstaller的自动依赖检测无法识别Hydra的内部插件模块,需通过--hidden-import参数显式指定:
修改打包命令为:

pyinstaller --noconfirm --onefile --console --paths "D:/Programmieren/Python/StorageRoom/.venv/Lib/site-packages" --hidden-import hydra._internal.core_plugins --hidden-import hydra._internal.utils --hidden-import hydra.core.plugins --hidden-import hydra._internal.default_plugins "D:/Programmieren/Python/StorageRoom/src/main.py"

2. 调整Hydra配置路径适配打包环境

打包成单文件exe后,运行时的工作路径与原脚本路径可能不一致,修改@hydra.main的config_path为相对于exe的路径:

@hydra.main(version_base=None, config_path="./conf", config_name="config")

若conf目录与exe同目录,也可省略config_path让Hydra自动查找:

@hydra.main(version_base=None, config_name="config")

3. 使用.spec文件自定义打包配置(推荐)

若命令行参数过于繁琐,可生成并编辑.spec文件:

  1. 生成.spec文件:
pyinstaller --onefile --console "D:/Programmieren/Python/StorageRoom/src/main.py"
  1. 打开生成的main.spec,在hiddenimports列表中添加Hydra相关模块:
hiddenimports=['hydra._internal.core_plugins', 'hydra._internal.utils', 'hydra.core.plugins', 'hydra._internal.default_plugins'],
  1. 基于.spec文件打包:
pyinstaller main.spec

4. 保持配置目录与exe同目录

确保打包后conf和logs目录与main.exe处于同一层级,当前输出结构已符合要求,无需调整。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 11:35:28