使用Python 3.2和cx_Freeze创buildWindows可执行文件

所以我试图将一个python脚本打包成一个可以在Windows机器上运行而不需要python安装的exe文件。 我正在运行WIn7&我的应用程序使用pywin32&launcher是一个名为console.py的文件,它接受一些命令行参数并执行另一个脚本

我创build了一个setup.py文件,我使用下面的安装文件运行python setup.py build

from cx_Freeze import setup, Executable setup( name = "OneNote Email Notifications", version = "0.1", description = "An email notifier for OneNote", executables = [Executable("console.py")] ) 

这返回了以下错误,

 Traceback (most recent call last): File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2 7, in <module> exec(code, m.__dict__) File "console.py", line 1, in <module> File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\notificati ons.py", line 1, in <module> import application File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\applicatio n.py", line 1, in <module> import ApplicationServer File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\Applicatio nServer.py", line 5, in <module> win32com.client.gencache.Rebuild() File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 649, in Rebuild _SaveDicts() File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 65, in _SaveDicts f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb") File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 141, in GetGeneratePath f = open(fname,"w") IOError: [Errno 2] No such file or directory: 'C:\\Users\\Varun\\Desktop\\My Dro pbox\\OnePy\\OM\\Notifications v0.2\\build\\exe.win-amd64-3.2\\library.zip\\win3 2com\\gen_py\\__init__.py' 

所以我想也许有一个问题读入zipfile,并决定运行生成没有创buildlibrary.zip。 所以我改变了setup.py

 from cx_Freeze import setup, Executable setup( name = "OneNote Email Notifications", version = "0.1", description = "An email notifier for OneNote", options = {"build_exe": { "create_shared_zip": False, "append_script_to_exe": True, "include_in_shared_zip": False, } }, executables = [Executable("console.py")] ) 

现在我收到以下错误信息:

 Traceback (most recent call last): File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2 7, in <module> exec(code, m.__dict__) File "console.py", line 1, in <module> File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\notificati ons.py", line 1, in <module> import application File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\applicatio n.py", line 1, in <module> import ApplicationServer File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\Applicatio nServer.py", line 5, in <module> win32com.client.gencache.Rebuild() File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 649, in Rebuild _SaveDicts() File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 65, in _SaveDicts f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb") File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 141, in GetGeneratePath f = open(fname,"w") IOError: [Errno 2] No such file or directory: 'C:\\Users\\Varun\\Desktop\\My Dro pbox\\OnePy\\OM\\Notifications v0.2\\build\\exe.win-amd64-3.2\\console.exe\\win3 2com\\gen_py\\__init__.py' 

尝试包括win32com.gen_py包。

您可以随时查看创建的zip文件,并查看目录是否存在(或者您已经完成了,直到一切正常)。

更改为以下

 #.... executables = [Executable("console.py", packages=[''win32com.gen_py])] #....