所以我试图将一个python脚本打包成一个可以在Windows机器上运行而无需安装python的exe。我正在运行WIn7&我的应用程序使用pywin32&启动程序是一个名为console.py的文件,它接受几个命令行参数并执行另一个脚本
我创建了一个setup.py文件,我使用以下安装文件运行python setup.py构建
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时遇到了一个问题,并决定在不创建library.zip的情况下运行build。所以我将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'
答案 0 :(得分:2)
尝试包含win32com.gen_py包。
您可以随时查看创建的zip并查看目录是否存在(或者您已经完成 - 在一切正常之前不要压缩)。
更改为以下
#....
executables = [Executable("console.py", packages=[''win32com.gen_py])]
#....