2017-08-04 55 views
2

我無法將我從YouTube上的教程製作的遊戲變成cx_Freeze的可執行文件。我使用的是virtualenv,而cx_Freeze是5.0版本。在運行遊戲時,我收到一條消息:無法使用virtualenv和cx_Freeze將pygame轉換爲可執行文件

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文件。

回答

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等文件放到該文件夾​​中。

+0

我添加了我目前的setup.py文件,它與您列出的類似。 – Skiltvakt

+0

有沒有其他想法? – Skiltvakt

相關問題