cx_freeze won't create a correct .exe for python 3.1.1
我使用的是python 3.1.1,我一直在尝试编译今天早些时候编写的一个程序,我认为代码足够短,可以在下面发布。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | from tkinter import * class Application(Frame): """ GUI application that creates a story based on user input.""" def __init__(self, master): """ Initialize Frame.""" super(Application, self).__init__(master) self.grid() self.label1() self.label2() def label1(self): Label(self, text ="Shop Keeper 1.1", font = ("fixedsys", 72)).grid(row = 0, column = 0, sticky = W) def label2(self): Label(self, text ="Welcome to Shop Keeper 1.1!" ).grid(row = 1, column = 0, sticky = W) # create a label and text entry for a plural noun Label(self, text ="Block name:" ).grid(row = 2, column = 0, sticky = W) self.BlokID = Entry(self) self.BlokID.grid(row = 2, column = 1, sticky = W) # create a label and text entry for a verb Label(self, text ="Amount:" ).grid(row = 3, column = 0, sticky = W) self.Amound = Entry(self) self.Amound.grid(row = 3, column = 1, sticky = W) Label(self, text ="Name:" ).grid(row = 4, column = 0, sticky = W) self.nama = Entry(self) self.nama.grid(row = 4, column = 1, sticky = W) Label(self, text ="Desired price:" ).grid(row = 5, column = 0, sticky = W) self.desprice = Entry(self) self.desprice.grid(row = 5, column = 1, sticky = W) # create a submit button Button(self, text ="Submit order", command = self.submit ).grid(row = 6, column = 1, sticky = W) self.submit = Text(self, width = 75, height = 10, wrap = WORD) self.submit.grid(row = 7, column = 0, columnspan = 4) def submit(self): """ Fill text box with new story based on user input.""" # get values from the GUI BlockID = self.BlokID.get() amount = self.Amound.get() name = self.nama.get() price = self.desprice.get() emess = name emess +=" ordered" emess += amount emess +=" units of" emess += BlockID emess +=" at the price of" emess += price emess +=" each." emess +=" " # display the story self.submit.insert(0.0, emess) # main root = Tk() root.title("Shop Keeper 1.0") app = Application(root) root.mainloop() |
我已经尝试用cx-freeze编译它几个小时了,但运气不好。它创建文件夹,但当我单击.exe时,它会很快打开和关闭。在多次快速点击之后,我发现它缺少一些与tkinter相关的模块,在搜索了这里的论坛之后,我得出结论,它缺少模块。但我修不好!我已经按照建议添加了tcl8.5和tk8.5文件夹,但似乎没有修复它。我已经尽力了,所以我把这个问题作为最后的解决办法。创建的文件夹包含以下文件:
1 2 3 4 5 6 7 8 9 | _socket.pyd _tkinter.pyd library.zip mad_lib.exe python31.dll select.pyd tcl85.dll tk85.dll unicodedata.pyd |
请帮助!
我试过以下方法,对我来说效果很好。
使用ActiveState python 3.2.2.3(http://www.activestate.com/activepython/downloads)
然后我转到http://cx-freeze.sourceforge.net/下载并安装了用于python 3.2的msi(我使用的是64位)。
我把你的程序保存为c:scriptsshopekeeper.py
接下来我运行了:
1 | C:\Python32\Scripts\cxfreeze C:\Scripts\Shopkeeper.py --target-dir C:\cxfreezetest |
然后我运行了