使用 Python 3.2 和 Python 创建 Windows 可执行文件CX_冻结
所以我试图将python脚本打包成一个可以在Windows机器上运行的exe,而不需要安装python。我正在运行 WIn7 &我的应用程序使用 pywin32 &启动器是一个名为 console.py 的文件,它接受几个命令行参数并执行另一个脚本
我创建了一个 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'
所以我认为读取 zip 文件可能存在问题,并决定运行构建而不创建library.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'
So I'm trying to package a python script into an exe that can run on a Windows machine without needing a python install. I'm running WIn7 & my application uses pywin32 & the launcher is a file called console.py which takes in a couple of command line arguments and executes another script
I created a setup.py file upon which I ran python setup.py build, with the following setup file
from cx_Freeze import setup, Executable
setup(
name = "OneNote Email Notifications",
version = "0.1",
description = "An email notifier for OneNote",
executables = [Executable("console.py")]
)
That returned the following error,
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'
so I figured perhaps there was an issue reading into the zipfile and decided to run build without creating library.zip. So I changed setup.py to
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")]
)
and now I get the following error message:
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'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试包含 win32com.gen_py 包。
您可以随时查看创建的 zip 并查看该目录是否存在(或者像您所做的那样 - 在一切正常之前不要压缩)。
更改为以下内容
Try including the win32com.gen_py package.
You can always look in the created zip and see if the directory exists (or as you have done - don't zip until everything works well).
Change to the following