无法使用virtualenv和cx_Freeze将pygame转换为可执行文件

时间:2017-08-04 19:34:36

标签: python pygame virtualenv python-3.5 cx-freeze

我无法将使用youtube上的教程制作的游戏变成带有cx_Freeze的可执行文件。我使用的是virtualenv,而cx_Freeze是5.0版本。在运行游戏时,我收到一条消息:

libuv

以下是创建文件时的追溯。

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>`

图像与setup.py文件位于同一目录中。

1 个答案:

答案 0 :(得分:0)

在您的设置文件中使用它:

from cx_Freeze import setup,Executable
setup(name="NAME OF YOUR PROGRAM",
         version="1.0",
         description="as above",
         executables=[Executable("NAME OF THE SCRIPT.py")])

然后,将您的png文件拖到该文件夹​​中,并将其拖到与您的程序相同的文件夹中。

python setup.py build

最后将你的png,jpg等文件放到该文件夹​​中。