PyInstaller exe仅在从cmd

时间:2016-07-31 12:16:43

标签: python windows pyinstaller

我试图打包我写入exe文件的python工具,以便在Windows 10上使用。据我所知,exe是正确构建的。如果我从命令行运行它,它会加载并且一切正常。

但是,如果我尝试从资源管理器中运行该工具(双击图标),我会得到一个"无法执行脚本"错误。我尝试使用--debug开关构建它,希望我可以在cmd关闭之前快速捕获任何输出,但它太快了。

我用来构建工具的行是:

pyinstaller.exe --onefile --debug --console --icon=C:\Users\Ross\Desktop\gtt\assets\icon.ico --hidden-import xlrd gtt.py

在我开始使用reportlab模块之前,它工作得很好:

from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER
from reportlab.lib.pagesizes import letter, portrait
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Table, TableStyle, Paragraph, Spacer

当我使用调试开关运行它时,命令行绝对没有关于错误的输出: Screenshot showing tool running in cmd

我已尝试过以下操作,但没有任何效果。

  • - noupx
  • - onedir
  • - onefile

总结一下,为什么PyInstaller exe文件在从命令行运行时有效,而不是从Windows GUI运行?

编辑:问题似乎与PyQt4有关。我回到了一个提交,我从tkinter切换到Qt,问题仍然存在。使用tkinter的上一个版本可以从GUI加载。

1 个答案:

答案 0 :(得分:0)

我明白了!

我必须将gui.ui文件转换为包。

  1. 我创建了包" gui,"包含空的__init __。py
  2. 我运行pyuic4 gui.ui -o gui.py将gui.ui代码转换为Python
  3. 我将gui.ui和gui.py文件移动到gui目录
  4. 在我的主程序代码中,我导入了模块:from gui.gui import *
  5. 希望能帮助其他人!

相关问题