使用 py2exe 创建的可执行文件出现问题
我有一个用 python 编写的应用程序,它使用 pygtk 构建 GUI,还包含一些用于窗口构建的空地文件。
我的问题是,当我从 cmd 运行它时,我的应用程序工作正常,但是当我使用 py2exe 创建 exe 时,应用程序不会启动,但它会创建我在日志应用程序中写入的空日志文件。
我的 setup.py 看起来像:
from distutils.core import setup
import os
import pygtk
import py2exe
setup(
name = 'ABC',
description = 'blah blah blah',
author = 'XYZ',
version = '0.1',
windows = [
{
'script': 'filename.py',
'icon_resources': [(1, "logo.ico")],
}
],
options = {
'py2exe': {
'packages':'encodings',
'includes': 'cairo, pango, pangocairo, atk, gobject,gio',
}
},
data_files=[
'logo.png', 'bg.png', 'completed.png', 'down.png','up.png',
'processing.gif', 'cygcrypto-0.9.8.dll', 'cyggcc_s-1.dll',
'cygiconv-2.dll', 'cygpopt-0.dll', 'cygssp-0.dll', 'cygwin1.dll',
'cygz.dll', 'prog.exe','prog2.exe', 'prog3.exe',
'Login.glade', 'settings_lib.glade',
'Microsoft.VC90.CRT.manifest', 'msvcm90.dll','etc.zip',
'lib.zip', 'msvcp90.dll', 'msvcr90.dll', 'share.zip'
])
可能是什么问题?
I have an application written in python which uses pygtk to built GUI, also some glade files are included for window building.
My problem is my application works fine when i run it from cmd, but when i create an exe with py2exe the application doesn't start, but it creates the empty log file which i am writing in application for logs.
my setup.py looks like :
from distutils.core import setup
import os
import pygtk
import py2exe
setup(
name = 'ABC',
description = 'blah blah blah',
author = 'XYZ',
version = '0.1',
windows = [
{
'script': 'filename.py',
'icon_resources': [(1, "logo.ico")],
}
],
options = {
'py2exe': {
'packages':'encodings',
'includes': 'cairo, pango, pangocairo, atk, gobject,gio',
}
},
data_files=[
'logo.png', 'bg.png', 'completed.png', 'down.png','up.png',
'processing.gif', 'cygcrypto-0.9.8.dll', 'cyggcc_s-1.dll',
'cygiconv-2.dll', 'cygpopt-0.dll', 'cygssp-0.dll', 'cygwin1.dll',
'cygz.dll', 'prog.exe','prog2.exe', 'prog3.exe',
'Login.glade', 'settings_lib.glade',
'Microsoft.VC90.CRT.manifest', 'msvcm90.dll','etc.zip',
'lib.zip', 'msvcp90.dll', 'msvcr90.dll', 'share.zip'
])
What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在使用 py2exe 和 py2app 等工具时也遇到过很多次这样的问题。
IIRC,很多时候这是由于双击 .exe 时 Python 进程的工作目录非常不同造成的。您可能需要在 Python 程序的启动中添加一些代码来记录 os.getcwd() 的值。
另一件棘手的事情是您必须确保 py2exe 捆绑在所有您的程序正在使用的 Python 模块。从命令行运行时,您使用的是包含所有这些模块的 Python。双击 .exe 时,您使用的 Python 与您在
setup.py
中明确列出的模块一起捆绑到可执行文件中 - 很容易错过其中一个。要找到这一点,您可以在导入周围放置 try/ except 子句,然后将ImportError
异常记录到文件中。I had problems like this too quite a few times when using tools like py2exe and py2app.
IIRC, many times it was caused by the Python process's working directory being something very different when the .exe is double-clicked. You may want to add some code to the startup of your Python program that logs the value of
os.getcwd()
The other thing that is tricky is that you have to make sure that py2exe bundles in all the Python modules that your program is using. When running from the command-line, you're using a Python that has all those modules. When double-clicking the .exe, you're using a Python that is bundled into the executable along with modules that you've explicitly listed in
setup.py
-- it's very easy to miss one. To find this, you could put try/except clauses around your imports and then logging theImportError
exceptions to a file.