是否有将 Openpyxl 与 Pyinstaller 一起使用的解决方法?

Is there a workaround for using Openpyxl with Pyinstaller?

我在尝试冻结导入 openpyxl 的脚本时遇到错误,并且没有生成 .exe。 如果脚本仅包含 'import openpyxl'.

,则会出现相同的错误

我目前正在使用 Python 3.7.1、Pyinstaller 3.6 和 Openpyxl 2.5.12。我通过将脚本复制到 Anaconda 脚本文件夹中来冻结脚本,然后使用 powershell 调用 pyinstaller 将脚本冻结为单个 .exe。我已经使用这种方法成功地冻结了一些其他脚本。

网上搜了一下答案,openpyxl不喜欢被冻结,但是好几个地方好像都说已经找到解决方法了

我已经尝试了一些建议的解决方案,包括 placing the hook file in the directory 并在 powershell window 中将其作为隐藏导入调用: .\pyinstaller --hidden-import=openpyxl --onefile -w 'script.py'

但是,我发现没有任何效果。我的脚本相当大,我宁愿不必使用不同的 excel 模块重新编写它。有没有办法冻结我的脚本,让其他人无需安装就可以使用它python?

尝试使用 cx_freeze 它通常会减少错误。保存下面给出的文件名和 运行 build.bat 文件

setup.py

import cx_Freeze
from cx_Freeze import * 

setup (
    name = "give_name",
    options = {'build_exe':{'packages': ['package_name']}},
    executables = [
        Executable(
            "give_name.py", 

        )

    ]

)

build.bat

py setup.py build