cx_Freeze and Python 3.3

社会主义新天地 提交于 2019-12-08 03:06:07

问题


So, I have some Python 3.3 code that I need to make an .exe from on Windows. I discovered the only way to do it is using 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:

installing/using cx_freeze

When I try to run "python setup.py build" from cmd I get:

"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. Both Python and cx_Freeze I installed are 64-bit versions. Version of cx_Freeze I installed was: 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.

Please also note I'm a programming beginner.


回答1:


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! I was using Pygame to make the game if anyone needs to know.

So, here's shortly what I did after the step in the other answer I gave:

This is the setup.py I used:

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. 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. This wasn't possible to do when I opened the .exe from Windows because the window would close too fast.

Other than files that my code required, it also wanted some other .py files. Namely:

re.py
sre_compile.py
sre_constants.py
sre_parse.py

I copied them from python (c:\Python33\Lib) to my game folder.

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).

I've spent 9 hours in two days to figure all this out. Hope it helps other beginners.




回答2:


You need to make python a cmd command.

  1. Right click on the windows button
  2. Click System
  3. Click 'Advanced System Settings'
  4. Click 'Environment Variables'
  5. Under the 'System Variables' section, click on the 'Path' variable
  6. Once highlighted, click edit.
  7. Type in the new path (ex: C:\Python34>) and click 'OK'

I hope this helps. Orrrr... you typed cx_Freeze with a little f. oh, i just noticed you found your answer.



来源:https://stackoverflow.com/questions/16753870/cx-freeze-and-python-3-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!