所以我想从一个小游戏制作一个.exe文件但是当我尝试构建它时,当我输入:
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 :(得分: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然后您必须将该特殊文件放入您的文件夹。执行它后,拖动 png 文件到文件夹到你的程序的同一文件夹。
所以打开与程序在同一目录中的终端(cmd),写;
python setup.py build
然后将您的png,jpg等文件放入该文件夹。就是这样。
Here我为您录制视频。在setup.py和您的脚本保留的文件夹中,单击 shift +右键单击并在那里打开终端。例如,我在视频中拖动apple.png,因此您必须将所有特殊文件放在我放入视频的位置。
请确保您的脚本以#!/ usr / bin / env python 开头。否则Python找不到Python目录并抛出错误没有模块等。总是用它来启动你的脚本。
示例:
#!/usr/bin/env python
import pygame,random
import ChuckNorris
pygame.init()
#codes