【发布时间】:2019-06-03 08:10:28
【问题描述】:
我的cx_Freeze 应用程序在我打开它时关闭,并且没有打印任何错误。安装文件运行没有错误。我相信这与我的主要代码中的导入有关。我使用了 python 3.6.5 cx_Freeze 6.0b1 和 windows 10。
setup.py
import os
from cx_Freeze import setup, Executable
include_lst = []
package_lst = ['numpy', 'scipy', 'pulp', 'pubsub', 'sqlite3', 'pandas',
'wx', 'functools', 'sklearn', 'numpy.core._methods']
exclude_lst = ['matplotlib', 'tkinter', 'PyQt4.QtSql', 'PyQt5',
'PyQt4.QtNetwork', 'PyQt4.QtScript', 'sqlalchemy']
base = None
setup (
name='test',
version='0.01',
author='test',
author_email='Omitted',
options={'build_exe':
{'packages': package_lst,
'excludes': exclude_lst,
'include_files': include_lst
}
},
executables=[Executable('main_.py', base=base, icon=icon_file)]
)
当我冻结这个基本示例时,它可以正常工作
main.py
import wx
class MasterPage (wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.createFrame()
def createFrame(self):
self.width, self.height = wx.GetDisplaySize()
self.SetTitle('Test')
self.SetSize(wx.Size((self.width-50, self.height-50)))
self.SetMinSize((1080, 720))
self.W, self.H = self.GetSize()
self.Bind(wx.EVT_CLOSE, self.onQuit)
self.Centre()
def onQuit(self, event):
"""Checks to make sure the user wants to leave the program"""
dlg = wx.MessageDialog(self,'Do you really want to quit?',
'Confirm Exit',
wx.ICON_QUESTION|wx.OK|wx.CANCEL )
result = dlg.ShowModal()
dlg.Destroy
if result == wx.ID_OK:
self.Destroy()
if __name__.endswith('__main__'):
app = wx.App()
MasterPage(None).Show()
app.MainLoop()
但是当我在import wx 行上方添加import pandas 或import <any module> 时,cx_Freeze 应用程序一打开它就会关闭
main.py
import pandas
import wx
class MasterPage (wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.createFrame()
def createFrame(self):
self.width, self.height = wx.GetDisplaySize()
self.SetTitle('Test')
self.SetSize(wx.Size((self.width-50, self.height-50)))
self.SetMinSize((1080, 720))
self.W, self.H = self.GetSize()
self.Bind(wx.EVT_CLOSE, self.onQuit)
self.Centre()
def onQuit(self, event):
"""Checks to make sure the user wants to leave the program"""
dlg = wx.MessageDialog(self,'Do you really want to quit?',
'Confirm Exit',
wx.ICON_QUESTION|wx.OK|wx.CANCEL )
result = dlg.ShowModal()
dlg.Destroy
if result == wx.ID_OK:
self.Destroy()
if __name__.endswith('__main__'):
app = wx.App()
MasterPage(None).Show()
app.MainLoop()
我也尝试将导入放在 try except 语句中,它仍然无法打开并且没有错误打印
main.py
try:
import pandas
except Exception as e:
print(e)
import wx
class MasterPage (wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.createFrame()
def createFrame(self):
self.width, self.height = wx.GetDisplaySize()
self.SetTitle('Test')
self.SetSize(wx.Size((self.width-50, self.height-50)))
self.SetMinSize((1080, 720))
self.W, self.H = self.GetSize()
self.Bind(wx.EVT_CLOSE, self.onQuit)
self.Centre()
def onQuit(self, event):
"""Checks to make sure the user wants to leave the program"""
dlg = wx.MessageDialog(self,'Do you really want to quit?',
'Confirm Exit',
wx.ICON_QUESTION|wx.OK|wx.CANCEL )
result = dlg.ShowModal()
dlg.Destroy
if result == wx.ID_OK:
self.Destroy()
if __name__.endswith('__main__'):
app = wx.App()
MasterPage(None).Show()
app.MainLoop()
我什至在import 语句之前和import 语句之后添加了一个打印语句,第一个打印语句运行然后应用程序关闭。
main.py
print('app started')
import pandas
print('import worked')
import wx
class MasterPage (wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.createFrame()
def createFrame(self):
self.width, self.height = wx.GetDisplaySize()
self.SetTitle('Test')
self.SetSize(wx.Size((self.width-50, self.height-50)))
self.SetMinSize((1080, 720))
self.W, self.H = self.GetSize()
self.Bind(wx.EVT_CLOSE, self.onQuit)
self.Centre()
def onQuit(self, event):
"""Checks to make sure the user wants to leave the program"""
dlg = wx.MessageDialog(self,'Do you really want to quit?',
'Confirm Exit',
wx.ICON_QUESTION|wx.OK|wx.CANCEL )
result = dlg.ShowModal()
dlg.Destroy
if result == wx.ID_OK:
self.Destroy()
if __name__.endswith('__main__'):
app = wx.App()
MasterPage(None).Show()
app.MainLoop()
【问题讨论】:
标签: python-3.x cx-freeze