Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Freezing code to .exe
#1
I am having a problem. I want to convert a project of mine to an exe file. So I just created a test file to attempt to figure out how to do it. Here is my problem. I have a simple script in a file named Main. All it does is just open a pygame window.
import pygame

screen = pygame.display.set_mode([300,300])
Then I have the file with the information to create the exe file.
import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

executables = [
    Executable('Main.py', base=base, icon="icon.ico")
]

setup(name='test',
      version='0.1',
      description='test',
      executables=executables
      )

The thing is that when I then create the exe the exe file does not have any of the information I give it. The name of it is just the same as the file with the script in it.(Main) It has not version number and no description. The only thing it does have is the icon image. Also it wants to put every python file that comes with python into the zip file that is created even though I don't use all of that in my program, but that also could just be how it works. The point is how do I at least get it to give the exe file the proper information? P.S. I run it by opening the command window and typing python setup.py build which is how every youtube video shows to do it but none of them ever explain why this problem is happening.
Reply
#2
It looks like you can exclude certain packages or include specific ones, but it says it auto-detects what's needed.  ...it's possible pygame needs a lot, though.
http://cx-freeze.readthedocs.io/en/lates...utils.html Wrote:
import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = "guifoo",
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable("guifoo.py", base=base)])
I don't know enough about it to know why the version/filename aren't being honored.
Reply
#3
Quote:Also it wants to put every python file that comes with python into the zip file that is created even though I don't use all of that in my program
i always just include it all into the exe. Dont quote me on this, but i think i recall there is no same option for cx freeze? I mean to the point where you just are left with the exe and nothing else. Its been a long time since i used it.

You can use exclude to disallow python modules to be added

This is my setup file for py2exe which zipfile None puts it into the exe, and compressed puts all the DLL's the other stuff into the exe. The only thing i have to worry about is the resources for my game. The hassle of splitting out the DLL's and python intepreter isnt worth it for small games. I also think it makes it easier for uber noobs to figure out, etc.

This is setup is specifically tailored for pygame too. 
import os
import sys
import py2exe
from distutils.core import setup

origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
    dlls = ("libfreetype-6.dll", "libogg-0.dll", "sdl_ttf.dll")
    if os.path.basename(pathname).lower() in dlls:
        return 0
    return origIsSystemDLL(pathname)
py2exe.build_exe.isSystemDLL = isSystemDLL

sys.argv.append('py2exe')
setup(options={'py2exe': {'bundle_files': 1, 'compressed': True}},
      windows=[{'script': "game.py"}],
      zipfile=None)
I normally could care less about the version/desc, and just glad that the exe works. But i use time as the version and to keep track of exe age as you will see in the following links

another py2exe setup example
https://github.com/metulburr/random/blob..._py2exe.py

cxfreeze setup
https://github.com/metulburr/random/blob...xfreeze.py
Recommended Tutorials:
Reply
#4
Ok, well I guess this at least helps me a little bit.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  While Loop Variable Freezing? stylingpat 13 6,487 Feb-25-2021, 10:42 AM
Last Post: Abdullah

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020