Skip to main content
 首页 » 编程设计

python之使用Py2exe创建exe后出错

2025年05月04日7lautakyan007

Py2exe 似乎运行良好,尽管它确实提到可能缺少一些模块。

我一直在使用 windows 选项(在我的 py2exe 脚本中)来删除控制台窗口,但我意识到即使在我关闭 gui 窗口后进程仍然保持打开状态,即我仍然可以在任务管理器中看到进程。 . 所以我切换到使用控制台选项,发现那里打印了以下错误。我相信此错误会阻止应用程序关闭。除此之外,该应用程序运行良好。

我尝试从一个非常简单的 wxPython GUI 应用程序创建一个 exe,但即便如此我仍然会收到此错误,但是我从不包含 wxPython 的应用程序创建可执行文件没有问题。

Debug: src/helpers.cpp(140): 'createActCtx' failed with error 0x0000007b (the filename, directory name, or volume label syntax is incorrect.).) 

Python: 2.6.6

wxPython: 2.8.11.0

Windows 7

py2exe: 0.6.9

# -*- coding: utf-8 -*- 
 
 
from distutils.core import setup 
import py2exe 
import glob 
 
 
 
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger', 
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl', 
            'Tkconstants', 'Tkinter'] 
 
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll', 'tk84.dll',]#'msvcp90.dll'] 
 
packages = []#'wx.lib.pubsub'] 
 
 
data_files = [("resources", ['resources/1187958_90214884.jpg'])] 
packages = ['wx.lib.pubsub',] 
options = {'py2exe': {'compressed': 3, 
                          'optimize': 2, 
                          'excludes': excludes, 
                          'packages': packages, 
                          'dll_excludes': dll_excludes, 
                          'bundle_files': 1, 
                          'dist_dir': 'dist', 
                          'xref': False, 
                          'skip_archive': False, 
                          'ascii': False, 
                          'packages': packages, 
                        'custom_boot_script': '', 
                         } 
                }   
 
#windows=[{'script':'gui.py'}] 
 
 
for script in ["gui.py"]: 
    windows=[{ 
        'script':[script] 
    }] 
 
    setup(options=options, console=[script], zipfile=None, data_files=data_files)                         

请您参考如下方法:

我在使用 py2exe 将 wxPython 代码编译为 exe 时遇到了一些小麻烦。我有一个教程,您可以在此处试用:

http://www.blog.pythonlibrary.org/2010/07/31/a-py2exe-tutorial-build-a-binary-series/

我在使用 2.8.11.0 中包含的新版 pubsub 时遇到了一些问题。您可以在此处阅读主题:http://bit.ly/emoHEr

那天我最终恢复到以前版本的 wx 主要是因为我没有时间弄清楚我做错了什么。我不知道这是否是您遇到的问题。