Python使用py2exe将所有文件/图像/声音压缩在一个可执行文件中



当我试图用py2exe将我的Python程序转换为exe时,首先一切都很好,直到我试图将所有文件捆绑到一个可执行文件中。首先,所有的图像和声音都不是捆绑在一起的,而是在distfolder中。我的.dll文件也有同样的问题,我必须手动导入程序才能运行。那么,我如何将所有的文件,如图像,dll和声音导入到exe中呢?接下来,当我尝试像这样执行exe时,它在cmd:中给了我这个错误

Fatal Python error: (pygame parachute) Segmentation Fault This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information.

这是我的设置文件:

from distutils.core import setup
import py2exe
import Tkinter as tk
from itertools import cycle
import pygame
import random
import glob
setup(
    data_files=[("libogg-0.dll"),
                ('.', glob.glob('*.gif')),
                ('.', glob.glob('*.wav'))],
    options = {"py2exe": {"includes": ['Tkinter', 'random', 'itertools', 'pygame'],
                          "excludes": ['AppKit', 'Carbon', 'Carbon.Files', 'Foundation', 'Numeric', 'OpenGL.GL', 'OpenGL.GLU', 'RandomArray', '_scproxy', '_sysconfigdata', 'copyreg', 'dummy.Process', 'numpy', 'opencv', 'pkg_resources', 'psyco', 'queue', 'test.__main__', 'test.event_test', 'test.test_utils', 'test.test_utils.async_sub', 'test.test_utils.run_tests', 'test.test_utils.test_runner', 'test.test_utils.unittest_patch', 'urllib.parse', 'vidcap', 'win32api', 'win32con', 'win32file', 'win32pipe', 'winreg','pygame.sdlmain_osx'],
                          "dll_excludes": ['OLEAUT32.dll','USER32.dll', 'IMM32.dll', 'SHELL32.dll', 'ole32.dll', 'COMDLG32.dll', 'COMCTL32.dll', 'ADVAPI32.DLL', 'WS2_32.dll', 'GDI32.dll', 'WINMM.DLL', 'KERNEL32.dll', 'SDL_ttf.dll', 'libogg-0.dll'],
                          "packages": ['pygame'],
                          "bundle_files": 1,
                          "compressed": True
                         }
              },
    console=['test.py'],
    zipfile = None
)

如果还有什么不清楚的地方,请随时评论答案。对不起,如果我的英语不好。

首先,您不需要导入py2exe

其次,键入python -m auto_py_to_exe,然后屏幕出现。在那里,通过浏览选择文件,选择in one fileconsole based,然后转换。

希望这能有所帮助。

相关内容

最新更新