pygame + py2exe = bad exe. why?

M.E.Farmer mefjr75 at hotmail.com
Tue Dec 28 15:25:54 EST 2004


Hello Erik,
Have you ever seen pygame2exe.py?
It is a py2exe script for pygame.
I found this on my hard drive from last year.
I have never created an exe from pygame using this script , so it might
be useless ;)
Do a search might be updated by now.....can not remember where I got it
from ( maybe pygame website? )


py>#make standalone, needs at least pygame-1.5.3 and py2exe-0.3.1
py>from distutils.core import setup
py>import sys, os, pygame, shutil
py>import py2exe
py>
py>#setup the project variables here.
py>#i can't claim these will cover all the cases
py>#you need, but they seem to work for all my
py>#projects, just change as neeeded.
py>
py>
py>script = "aliens.py"            #name of starting .PY
py>icon_file = ""                  #ICO file for the .EXE (not working
well)
py>optimize = 2                    #0, 1, or 2; like -O and -OO
py>dos_console = 1                 #set to 0 for no dos shell when run
py>extra_data = ['data', 'readme.txt'] #extra files/dirs copied to game
py>extra_modules = ['pygame.locals']   #extra python modules not auto
found
py>
py>#use the default pygame icon, if none given
py>if not icon_file:
py>    path = os.path.split(pygame.__file__)[0]
py>    icon_file = '"' + os.path.join(path, 'pygame.ico') + '"'
py>#unfortunately, this cool icon stuff doesn't work in current py2exe
:(
py>#icon_file = ''
py>
py>
py>#create the proper commandline args
py>args = ['py2exe', '--force', '-O'+`optimize`]
py>args.append(dos_console and '--console' or '--windows')
py>if icon_file:
py>    args.append('--icon')
py>    args.append(icon_file)
py>args.append('--force-imports')
py>args.append(','.join(extra_modules))
py>#args.append(','.join(pygame_modules + extra_modules))
py>sys.argv[1:] = args + sys.argv[1:]
py>
py>project_name = os.path.splitext(os.path.split(script)[1])[0]
py>
py>
py>#this will create the executable and all dependencies
py>setup(name=project_name, scripts=[script])
py>
py>#also need to hand copy the extra files here
py>def installfile(name):
py>    dst = os.path.join('dist', project_name)
py>    print 'copying', name, '->', dst
py>    if os.path.isdir(name):
py>        dst = os.path.join(dst, name)
py>        if os.path.isdir(dst):
py>            shutil.rmtree(dst)
py>        shutil.copytree(name, dst)
py>    elif os.path.isfile(name):
py>        shutil.copy(name, dst)
py>    else:
py>        print 'Warning, %s not found' % name
py>
py>
py>
py>
py>pygamedir = os.path.split(pygame.base.__file__)[0]
py>installfile(os.path.join(pygamedir,
pygame.font.get_default_font()))
py>installfile(os.path.join(pygamedir, 'pygame_icon.bmp'))
py>for data in extra_data:
py>    installfile(data)

This is probably a complete mess by the time it reaches you.
I started every line with py> so just unwrap the lines that didn't make
it.
Hth,
M.E.Farmer




More information about the Python-list mailing list