【问题标题】:ModuleNotFoundError: No module named 'x' because can't find the module folder, PyInstallerModuleNotFoundError:没有名为“x”的模块,因为找不到模块文件夹,PyInstaller
【发布时间】:2021-02-10 20:52:25
【问题描述】:

我的代码(test.py)看起来像这样(简化):

from app.utils import conversion

(code)

当我尝试使用 PyInstaller 制作可执行文件时,.exe 在我导入通用模块时工作。但是,当我在代码开头使用“从 app.utils 导入转换”时收到以下错误消息:

ModuleNotFoundError: No module named 'app'

.exe 不会运行。

我的项目是这样组织的(简化):

project/app/test.py

project/app/utils/conversion.py

我在控制台中输入的指令是:

pyinstaller --onefile test.py

知道为什么以及如何克服这个问题吗?谢谢!

【问题讨论】:

标签: python module compiler-errors pyinstaller exe


【解决方案1】:

这是我解决问题的方法:

.spec file中,添加了hiddenimports中缺失的app模块:

hiddenimports=["app"]

然后为了编译可执行文件,我运行 .spec 文件或 .py 文件。

pyinstaller --onefile test.spec

【讨论】:

    猜你喜欢
    • 2021-03-26
    • 1970-01-01
    • 1970-01-01
    • 2019-12-02
    • 2020-10-03
    • 2021-05-16
    • 2021-10-26
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多