Pyinstaller .exe无法产生预期的结果 [英] Pyinstaller .exe does not produce expected outcome

查看:140
本文介绍了Pyinstaller .exe无法产生预期的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is the first time that I have used pyinstaller to build an .exe of my .py on a windows machine. I have successfully generated the .exe, but when I run the code it does not produce the .csv file that my code should produce.

顺便说一句,当我在IDE中运行脚本时,它会成功生成期望的.csv.底部是我的代码中应生成输出的部分.

On a side note, when I run my script within the IDE it successfully generates the .csv that I expect it to. The bottom is the part of my code that should generate the output.

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安装时,它说我已经在运行xlsxwriter

When run in the command prompt I get the error No module xlsxwriter, but when I try to run the pip install it says that I am already running xlsxwriter

推荐答案

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

It is possible that the program is not running correctly because the .exe was not bundled correctly, or perhaps the application may be closing because it is unable to import a package or find an external file, which prevents your application from launching. To view the error messages associated with running your executable, run the .exe file from the command prompt: /path/to/app/dist/MyApp.exe (in Command Prompt). This will allow you to observe any errors that may exist after the app was bundled. If the program does fail during an import statement, you may need to add a package to the hiddenimports list in the .spec file.

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

It is difficult for us to diagnose this problem without more information, but perhaps the output displayed in the command prompt will provide some more information.

****您的编辑建议捆绑的应用程序中至少不包含一个模块.

** ** Your edit suggests that at least one module was not included in the bundled app.

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

To add modules to the .spec file: Once you run pyinstaller, a .spec file will be generated in the directory containing your .py file. You can open this .spec file and add modules to the list named hiddenimports. For example: hiddenimports = ['xlsxwriter', 'any_other_modules']. Once you've updated your .spec file, run the pyInstaller command again with the .spec file: pyinstaller --some_options my_app.spec

-或-

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

To add modules at the command prompt: Run pyinstaller with the hiddenimports option: pyinstaller --hidden-import xlsxwriter my_app.py

有关更多信息,请参见文档.

See the docs for more information.

这篇关于Pyinstaller .exe无法产生预期的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆