【发布时间】:2018-01-12 19:59:24
【问题描述】:
我无法使用 cx_Freeze 将我根据 youtube 上的教程制作的游戏转换为可执行文件。我正在使用 virtualenv 并且 cx_Freeze 是 5.0 版。运行游戏时,我收到一条消息:
Fatal Python error: Py_Initialize: unable to load the file system codec
ImportError: No module named 'encodings'
Current thread 0x00002c24 (most recent call first):
以下是创建文件时的回溯。
(pygame) G:\Programming\scripts\Python\PyGame\compile_files>python setup.py build
running build
running build_exe
creating directory build\exe.win32-3.5
copying G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\bases\Console.exe -> build\exe.win32-3.5\Slither.exe
copying G:\Programming\scripts\Python\virtualenv\pygame\Scripts\python35.dll -> build\exe.win32-3.5\python35.dll
Traceback (most recent call last):
File "setup.py", line 12, in <module>
executables=executables
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "G:\python\Python35-32\Lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "G:\python\Python35-32\Lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "G:\python\Python35-32\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "G:\python\Python35-32\Lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "G:\python\Python35-32\Lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "G:\python\Python35-32\Lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 623, in Freeze
self._FreezeExecutable(executable)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 225, in _FreezeExecutable
self._AddVersionResource(exe)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 165, in _AddVersionResource
trademarks = exe.trademarks)
File "G:\Programming\scripts\Python\virtualenv\pygame\lib\site-packages\cx_Freeze\freezer.py", line 759, in __init__
parts = version.split(".")
AttributeError: 'NoneType' object has no attribute 'split'
(pygame) G:\Programming\scripts\Python\PyGame\compile_files>`
我的设置文件是:
import cx_Freeze
import os
os.environ['TCL_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "G:\\python\\Python35-32\\tcl\\tk8.6"
executables=[cx_Freeze.Executable("Game.py")]
cx_Freeze.setup(
name="Game",
options={"build_exe":{"packages":["pygame"],"include_files":["image1.png","image2.png"]}},
description="Game",
executables=executables
)
图像与 setup.py 文件位于同一目录中。
【问题讨论】:
标签: python pygame virtualenv python-3.5 cx-freeze