我把我设计的Python游戏转化成了exe格式。运行exe文件会出现闪烁并立即关闭,说明出现了错误。在命令提示符中运行也会出现错误,并记录下来:
Cannot load image: Playfield.png
Couldn't open images\Playfield.png
这段文字告诉我
load_image
块存在问题。我以前遇到过这种情况,当时是因为我没有一个images
目录。我尝试将
images
文件夹移动到dist
目录中,但是出现了以下错误:Traceback (most recent call last):
File "Table_Wars.py", line 728, in <module>
File "Table_Wars.py", line 51, in main
File "Table_Wars.py", line 236, in __init__
File "pygame\__init__.pyc", line 70, in __getattr__
NotImplementedError: font module not available
(ImportError: DLL load failed: The specified module could not be found.)
这是我第一次使用py2exe,所以我不太确定发生了什么。原始的Python文件本身(Table_Wars.py)可以正常运行。
如果有帮助的话,整个Table_Wars文件夹的位置在我的桌面上的一个名为Games的文件夹内(C:\Users\Oventoaster\Desktop\Games\Table_Wars)。我正在运行Windows 7 32位操作系统。
根据要求,以下是我生成的output.txt:
Folder PATH listing for volume OS
Volume serial number is 7659-4C9C
C:\USERS\OVENTOASTER\DESKTOP\GAMES\TABLE_WARS
build
bdist.win32
winexe
bundle-2.7
collect-2.7
ctypes
distutils
email
mime
encodings
logging
multiprocessing
dummy
pygame
threads
unittest
xml
parsers
temp
dist
images
以下是我用于转换文件的setup.py:
from distutils.core import setup
import py2exe
setup(console=['Table_Wars.py'])
编辑:我尝试使用完整的 py2exe 示例。这个命令将创建 exe,但是出现了相同的“无法加载图像”错误。 将 images 文件夹放在与 exe 相同的文件夹中会创建一个“运行时错误:应用程序请求以不寻常的方式终止它。”
Slace Diamond 建议的代码缩写防止了 py2exe 找到 Table_Wars.py:
来自 cmd 的代码:
running py2exe
*** searching for required modules ***
error: Table_Wars.py: No such file or directory.
setup
和Table_Wars
在同一目录下。如果需要,我会输入到python.exe和setup.py的完整路径。
编辑:我似乎越来越接近了。我将images
目录放在self.extra_datas
中,现在我得到了这个错误:
Fatal Python error: (segmentation fault)
This application has requested the runtime to terminate it in an unusual way. Please contact the application's suppourt team for more information
tree "C:\Users\Oventoaster\Desktop\Games\Table_Wars" > output.txt
并上传出现的 output.txt 文件?这将更好地帮助我们了解文件的位置。 - Nick ODellsetup.py
文件? - jdi