使用pyinstaller转换为exe后无法导入模块

问题描述 投票:-1回答:1

我已使用pyinstaller通过以下命令将python代码编译为.exe:

pyinstaller --onefile .\mycode.py

完成时没有错误,但是当我尝试使用.exe时,它给了我错误:

RuntimeError: Cannot import module **** which is needed to continue

而***是已明确安装的模块(当我使用python运行mycode.py时,它可以正常工作),并且当然会导入代码中。我该如何解决?感谢您的帮手。

python module exe pyinstaller
1个回答
0
投票

正如OP对问题的评论所说,他们正在使用importlib。 PyInstaller只能使用from *** import ***import ***格式读取导入。如果您想使用importlib__import__或任何其他不受支持的方法,请使用--hidden-import=***选项将导入添加到隐藏导入中。此选项可以多次使用。

© www.soinside.com 2019 - 2024. All rights reserved.