Pyinstaller.exe 未产生预期结果

2024-01-30

这是我第一次使用 pyinstaller 在 Windows 机器上构建 .py 的 .exe。我已成功生成 .exe,但是当我运行代码时,它不会生成我的代码应生成的 .csv 文件。

附带说明一下,当我在 IDE 中运行脚本时,它成功生成了我期望的 .csv。底部是我的代码中应生成输出的部分。

writer = pd.ExcelWriter('Desired_Output.xlsx', engine= 'xlsxwriter')
df3.to_excel(writer, sheet_name='Output')

#Get the xlsxwriter workbook and worksheet objects
workbook = writer.book
worksheet = writer.sheets['Output']

# Add some cell formatting and save the contents
format1 =  workbook.add_format({'left': 1, 'right': 1, 'top': 1, 'bottom': 1, 'bg_color': 'gray' })
format2 = workbook.add_format({'bottom': 1})
format3 = workbook.add_format({'bottom': 1, 'font_size': 7, 'bg_color': '#98FB98'})
format4 = workbook.add_format({'right': 1, 'bottom': 1})
worksheet.set_column('B:B', 12, format1)
worksheet.set_column('C:N', 8, format2)
worksheet.set_column('L:L', 6, format3)
worksheet.set_column('N:N', 8, format4)
writer.save()

在命令提示符下运行时出现错误 没有模块 xlsxwriter,但是当我尝试运行 pip install 时,它说我已经在运行 xlsxwriter


程序可能无法正确运行,因为 .exe 未正确捆绑,或者应用程序可能因无法导入包或查找外部文件而关闭,从而阻止应用程序启动。要查看与运行可执行文件相关的错误消息,请从命令提示符运行 .exe 文件:/path/to/app/dist/MyApp.exe(在命令提示符中)。这将使您能够观察应用程序捆绑后可能存在的任何错误。如果程序在导入语句期间失败,您可能需要将包添加到hiddenimports.spec 文件中的列表。

如果没有更多信息,我们很难诊断这个问题,但命令提示符中显示的输出也许会提供一些更多信息。

**编辑:** 您的编辑表明捆绑的应用程序中至少未包含一个模块。

要将模块添加到 .spec 文件:运行 pyinstaller 后,将在包含 .py 文件的目录中生成 .spec 文件。您可以打开此 .spec 文件并将模块添加到名为的列表中hiddenimports。例如:hiddenimports = ['xlsxwriter', 'any_other_modules']。更新 .spec 文件后,使用 .spec 文件再次运行 pyInstaller 命令:pyinstaller --some_options my_app.spec

--or--

要在命令提示符处添加模块:使用以下命令运行 pyinstallerhiddenimports选项:pyinstaller --hidden-import xlsxwriter my_app.py

See the docs https://pythonhosted.org/PyInstaller/usage.html了解更多信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pyinstaller.exe 未产生预期结果 的相关文章

随机推荐