[英]cx_Freeze and Python 3.3
So, I have some Python 3.3 code that I need to make an .exe from on Windows. 因此,我有一些Python 3.3代码需要在Windows上制作一个.exe。 I discovered the only way to do it is using cx_Freeze.
我发现唯一的方法是使用cx_Freeze。 But, I haven't even got further than installation.
但是,我什至没有安装。 This question describes my problem perfectly (except I run Python 3.3), and has not been answered yet:
这个问题完美地描述了我的问题(除了运行Python 3.3),并且尚未得到回答:
installing/using cx_freeze 安装/使用cx_freeze
When I try to run "python setup.py build" from cmd I get: 当我尝试从cmd运行“ python setup.py build”时,我得到:
"importerror: no module named cx_freeze"
I can't get past this step, and have searched for a solution for an hour unsuccessfully. 我无法走过这一步,并且搜索解决方案已失败了一个小时。
In case it's relevant Python is installed at C:\\Python33. 如果相关的话,Python安装在C:\\ Python33。 Both Python and cx_Freeze I installed are 64-bit versions.
我安装的Python和cx_Freeze均为64位版本。 Version of cx_Freeze I installed was: cx_Freeze-4.3.1.win-amd64-py3.3.
我安装的cx_Freeze版本是:cx_Freeze-4.3.1.win-amd64-py3.3。 I tried reinstalling.
我尝试重新安装。 When I do "import cx_Freeze" in IDLE, it doesn't show any errors.
当我在IDLE中“导入cx_Freeze”时,它没有显示任何错误。
Please also note I'm a programming beginner. 另请注意,我是编程初学者。
Answer to the question is in my other answer. 问题的答案在我的其他答案中。 Make sure you read it first as this one expands on it.
确保您先阅读它,然后再对其进行扩展。
Ok, so after a few more hours of pain I got my game to run as an .exe on computers of people who don't have Python installed, which was my goal! 好的,经过几个小时的痛苦,我让我的游戏在没有安装Python的人的计算机上以.exe的身份运行,这是我的目标! I was using Pygame to make the game if anyone needs to know.
如果有人需要,我正在使用Pygame制作游戏。
So, here's shortly what I did after the step in the other answer I gave: 因此,这是我在给出其他答案的步骤后不久所做的事情:
This is the setup.py I used: 这是我使用的setup.py:
from cx_Freeze import setup, Executable
includefiles = ['add_all_your_files_here, example.png, example.mp3']
includes = []
excludes = []
packages = []
setup(
name = 'yourgame',
version = '1.0.0',
description = '',
author = 'John Doe',
author_email = 'johndoe@gmail.com',
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('yourgame.py')]
)
Note that I couldn't figure (and didn't want to bother) about how to include files from other folders, so I put them all together where the setup.py was. 请注意,我无法弄清楚(也不想打扰)如何包括其他文件夹中的文件,因此我将它们全部放在setup.py所在的位置。 I tried putting the relative path, but seems like I should've put the absolute.
我尝试过放置相对路径,但似乎我应该放置绝对路径。
To notice what files were missing I had to run the exe from cmd so when it would crash I could read what was the error. 为了注意到丢失了哪些文件,我必须从cmd运行exe,因此当崩溃时,我可以读取错误所在。 This wasn't possible to do when I opened the .exe from Windows because the window would close too fast.
当我从Windows打开.exe时,这是不可能的,因为窗口关闭得太快。
Other than files that my code required, it also wanted some other .py files. 除了我的代码需要的文件外,它还需要其他一些.py文件。 Namely:
即:
re.py
sre_compile.py
sre_constants.py
sre_parse.py
I copied them from python (c:\\Python33\\Lib) to my game folder. 我将它们从python(c:\\ Python33 \\ Lib)复制到了我的游戏文件夹。
The .exe was then able to run my game without problems on my and another computer that doesn't have python installed (no font problems for example, as I heard some people have). 然后,.exe可以在我和另一台未安装python的计算机上运行我的游戏而不会出现问题(例如,我听说有些人没有字体问题)。
I've spent 9 hours in two days to figure all this out. 我在两天内花了9个小时来解决所有这些问题。 Hope it helps other beginners.
希望它对其他初学者有所帮助。
You need to make python a cmd command. 您需要使python成为cmd命令。
I hope this helps. 我希望这有帮助。 Orrrr... you typed cx_Freeze with a little f.
Orrrr ...您用一点f键入了cx_Freeze。 oh, i just noticed you found your answer.
哦,我刚刚注意到您找到了答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.