2015-01-04 55 views
0

exe文件,所以我想從一個小遊戲讓一個.exe文件,但是當我嘗試建立它,當我鍵入:轉換pygame的文件,cx_Freeze

setup.py build 

它給人和錯誤pygame的不模塊

C:\Python33\Projects>setup.py build 
running build 
running build_exe 
Traceback (most recent call last): 
    File "C:\Python33\Projects\setup.py", line 11, in <module> 
    executables = executables 
    File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 362, in setup 
    distutils.core.setup(**attrs) 
    File "C:\Python34\lib\distutils\core.py", line 148, in setup 
    dist.run_commands() 
    File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands 
    self.run_command(cmd) 
    File "C:\Python34\lib\distutils\dist.py", line 974, in run_command 
    cmd_obj.run() 
    File "C:\Python34\lib\distutils\command\build.py", line 126, in run 
    self.run_command(cmd_name) 
    File "C:\Python34\lib\distutils\cmd.py", line 313, in run_command 
    self.distribution.run_command(command) 
    File "C:\Python34\lib\distutils\dist.py", line 974, in run_command 
    cmd_obj.run() 
    File "C:\Python34\lib\site-packages\cx_Freeze\dist.py", line 232, in run 
    freezer.Freeze() 
    File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 619, in Freeze 

    self.finder = self._GetModuleFinder() 
    File "C:\Python34\lib\site-packages\cx_Freeze\freezer.py", line 378, in _GetMo 
duleFinder 
    finder.IncludePackage(name) 
    File "C:\Python34\lib\site-packages\cx_Freeze\finder.py", line 686, in Include 
Package 
    module = self._ImportModule(name, deferredImports) 
    File "C:\Python34\lib\site-packages\cx_Freeze\finder.py", line 386, in _Import 
Module 
    raise ImportError("No module named %r" % name) 
ImportError: No module named 'pygame' 

C:\Python33\Projects> 

我的設置文件看起來像這樣:

import cx_Freeze 

executables = [cx_Freeze.Executable("racegame.py")] 

cx_Freeze.setup(
    name="Racegame", 
    options={"build_exe": {"packages": ["pygame"], 
          "include_files": ["racecar.png"]}}, 
    description="A race game", 

    executables = executables 
    ) 

回答

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")]) 

使用這個,我總是用這個執行。複製粘貼這個代碼到setup.py.And,然後你必須把這個特殊的文件放到你的文件夾中。當你執行它時,把你的文件拖到同一個文件夾中與您的程序。

所以用你的程序在同一個目錄下打開終端(cmd),寫入;

python setup.py build 

然後把你的PNG,JPG等文件,在該文件夾。而已。

Here我爲你錄製了一段視頻。在setup.py和您的腳本所在的文件夾中,單擊shift +右鍵單擊並在其中打開終端。例如,我在視頻中拖動apple.png,所以您必須將所有特殊文件放在視頻中。

請您務必腳本開始#!的/ usr /斌/包膜蟒蛇。否則,Python無法找到Python目錄並拋出該錯誤,無模塊等。總是開始你的腳本。

例子:

#!/usr/bin/env python 
import pygame,random 
import ChuckNorris 

pygame.init() 
#codes 
+0

我需要添加哪些腳本? – ViciousKangaroo

+0

將這些代碼複製並粘貼到_setup.py_ –