pygame + py2exe = bad exe. why?

E

Erik Bethke

Hello All,

Thank you:
First of all I want to say thank you all of you posters who have
already answered dozens of my questions as I have been learning Python
in my lurking & googling. Now for the first time I am stumped:

Background:
The setup script seems to be working, the files are all copied over to
the right place in the dist, and an exe is even produced. (I have
included the setup script below anyways.

The problem:
The exe crashes immediately on startup. Obviously it is failing to
find something - but what? During the p2exe's running it reports the
following warning:
The following modules appear to be missing
['AppKit', 'Foundation', 'objc']

Others have had this problem too:
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#77dc1cb83c0baede
http://groups-beta.google.com/group..._doneTitle=Back+to+Search&&d#09d451bc1e0c2cde

This guy says to ignore the warning above and instead include the font
(which I manually copied over, but it didn't help):
http://www.pick.ucam.org/~ptc24/pygame_py2exe.html
As well as 'other files' - which are???

I have also included the full output of py2exe below:

I would really, really appreciate someone setting me on the right track
to whatever is the current method for producing windows exe's for
python 2.3.4 and pygame!! Please. This has to be a straightforward
lack of some include directive or some such.

Thank you very much,
-Erik Bethke
www.gopetslive.com

REFERENCE MATERIAL BELOW

What I am running:
I am using:
windowsXP pro
python 2.3.4
pygame-1.6.win32-py2.3.exe
py2exe-0.5.4.win32-py2.3

Here is my setup script:
#!/usr/bin/env python
from distutils.core import setup
import py2exe
import glob

setup(windows=["mahjong.py"],
name='GoPets Mahjong',
version='0.3.1',
description='Mahjong for GoPets Users',
author='Erik Bethke',
author_email='(e-mail address removed)',
url='www.erikbethke.com',
py_modules=['mahjong','background','board','tile'],
data_files=[("images/classic", glob.glob("images/classic/*.*"))],
#package_dir={'mahjong': 'mahjong'},
#packages=['pygame'],
#package_data={'mahjong': ['images/classic/*.*']},
)

Full Verbose Output from py2exe:
running py2exe
running build_py
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'pygame.time'
creating python loader for extension '_sre'
creating python loader for extension 'pygame.joystick'
creating python loader for extension 'datetime'
creating python loader for extension 'pygame.mixer'
creating python loader for extension '_winreg'
creating python loader for extension 'pygame.surface'
creating python loader for extension 'pygame.key'
creating python loader for extension 'pygame.base'
creating python loader for extension 'pygame.draw'
creating python loader for extension 'pygame.sndarray'
creating python loader for extension 'pygame.transform'
creating python loader for extension 'pygame.rect'
creating python loader for extension 'pygame.rwobject'
creating python loader for extension 'pygame.mixer_music'
creating python loader for extension 'pygame.constants'
creating python loader for extension 'pygame.display'
creating python loader for extension 'pygame.movie'
creating python loader for extension 'pygame.mouse'
creating python loader for extension 'pygame.surfarray'
creating python loader for extension 'pygame.cdrom'
creating python loader for extension 'pygame.event'
creating python loader for extension 'pygame.font'
creating python loader for extension 'pygame.surflock'
creating python loader for extension 'pygame.image'
creating python loader for extension 'pygame.imageext'
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\_sre.py
to _sre.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\_winreg.py
to _winreg.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\datetime.py
to datetime.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.base.py
to pygame\base.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.cdrom.py
to pygame\cdrom.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.constants.py
to pygame\constants.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.display.py
to pygame\display.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.draw.py
to pygame\draw.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.event.py
to pygame\event.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.font.py
to pygame\font.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.image.py
to pygame\image.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.imageext.py
to pygame\imageext.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.joystick.py
to pygame\joystick.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.key.py
to pygame\key.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.mixer.py
to pygame\mixer.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.mixer_music.py
to pygame\mixer_music.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.mouse.py
to pygame\mouse.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.movie.py
to pygame\movie.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.rect.py
to pygame\rect.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.rwobject.py
to pygame\rwobject.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.sndarray.py
to pygame\sndarray.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.surface.py
to pygame\surface.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.surfarray.py
to pygame\surfarray.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.surflock.py
to pygame\surflock.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.time.py
to pygame\time.pyc
byte-compiling
E:\Python\Mahjong\MahjongProtoType\mahjong\build\bdist.win32\winexe\temp\pygame.transform.py
to pygame\transform.pyc
skipping byte-compilation of build\lib\background.py to background.pyc
skipping byte-compilation of build\lib\board.py to board.pyc
skipping byte-compilation of build\lib\tile.py to tile.pyc
skipping byte-compilation of e:\python23\lib\UserDict.py to
UserDict.pyc
skipping byte-compilation of e:\python23\lib\_strptime.py to
_strptime.pyc
skipping byte-compilation of e:\python23\lib\atexit.py to atexit.pyc
skipping byte-compilation of e:\python23\lib\calendar.py to
calendar.pyc
skipping byte-compilation of e:\python23\lib\copy.py to copy.pyc
skipping byte-compilation of e:\python23\lib\copy_reg.py to
copy_reg.pyc
skipping byte-compilation of e:\python23\lib\linecache.py to
linecache.pyc
skipping byte-compilation of e:\python23\lib\locale.py to locale.pyc
skipping byte-compilation of e:\python23\lib\macpath.py to macpath.pyc
skipping byte-compilation of e:\python23\lib\ntpath.py to ntpath.pyc
skipping byte-compilation of e:\python23\lib\os.py to os.pyc
skipping byte-compilation of e:\python23\lib\os2emxpath.py to
os2emxpath.pyc
skipping byte-compilation of e:\python23\lib\popen2.py to popen2.pyc
skipping byte-compilation of e:\python23\lib\posixpath.py to
posixpath.pyc
skipping byte-compilation of e:\python23\lib\random.py to random.pyc
skipping byte-compilation of e:\python23\lib\re.py to re.pyc
skipping byte-compilation of e:\python23\lib\repr.py to repr.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\__init__.py to pygame\__init__.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\color.py to pygame\color.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\colordict.py to
pygame\colordict.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\cursors.py to pygame\cursors.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\macosx.py to pygame\macosx.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\sprite.py to pygame\sprite.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\sysfont.py to pygame\sysfont.pyc
skipping byte-compilation of
e:\python23\lib\site-packages\pygame\version.py to pygame\version.pyc
skipping byte-compilation of e:\python23\lib\sre.py to sre.pyc
skipping byte-compilation of e:\python23\lib\sre_compile.py to
sre_compile.pyc
skipping byte-compilation of e:\python23\lib\sre_constants.py to
sre_constants.pyc
skipping byte-compilation of e:\python23\lib\sre_parse.py to
sre_parse.pyc
skipping byte-compilation of e:\python23\lib\stat.py to stat.pyc
skipping byte-compilation of e:\python23\lib\string.py to string.pyc
skipping byte-compilation of e:\python23\lib\types.py to types.pyc
skipping byte-compilation of e:\python23\lib\warnings.py to
warnings.pyc
*** copy extensions ***
*** copy dlls ***
*** copy data files ***
setting sys.winver for
'E:\Python\Mahjong\MahjongProtoType\mahjong\dist\python23.dll' to
'GoPets Mahjong'
copying e:\python23\lib\site-packages\py2exe\run_w.exe ->
E:\Python\Mahjong\MahjongProtoType\mahjong\dist\mahjong.exe
The following modules appear to be missing
['AppKit', 'Foundation', 'objc']
 
M

M.E.Farmer

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
 
E

Erik Bethke

M.E.Farmer said:
Hello Erik,
Have you ever seen pygame2exe.py?
It is a py2exe script for pygame.

Hello M.E. Farmer,

Thank you for your response. I looked into it and I discovered this
speedbump:

http://aspn.activestate.com/ASPN/Mail/Message/pygame-users/2244073

"pygame-users
Re: [pygame] Pygame2Exe problems
by Zak Arntson other posts by this author
Dec 7 2004 8:38PM messages near this date Re: [pygame] Pygame2Exe
problems | Re: [pygame] Pygame2Exe problems

Well heck, this means that the pygame2exe.py program needs to be
updated. If I can get it working tonight, I'll post my results. I'm
going to be studying, though, so I can't promise anything. (It may be
quicker for me to just put Python and Pygame onto the CD).


Hi, the --console and --force arguments are depreciated in newer
py2exe versions.

they are now part of the setup() call.scroll down a bit on
http://starship.python.net/crew/theller/py2exe/ and it describes the
new usage.

should look something like this:

# setup.py
from distutils.core import setup
import py2exe

setup(console=["myscript.py"])

#
python setup.py py2exe

-Knio
 
M

M.E.Farmer

Erik said:
# setup.py
from distutils.core import setup
import py2exe

setup(console=["myscript.py"])

#
python setup.py py2exe

-Knio

Erik glad to see you were able to track it down.
Have you been succesful in making the changes they mentioned?
M.E.Farmer
 
E

Erik Bethke

M.E.Farmer said:
Erik glad to see you were able to track it down.
Have you been succesful in making the changes they mentioned?
M.E.Farmer

Yes below is a simple script that works. The key was that pygame uses
freesansbold.ttf as the default font and that is not copied over in the
normal py2exe process. See the end of the setup script.

#!/usr/bin/env python
from distutils.core import setup
import py2exe, pygame
import glob, shutil

setup(windows=["mahjong.py"],
name='GoPets Mahjong',
version='0.3.1',
description='Mahjong for GoPets Users',
author='Erik Bethke',
author_email='(e-mail address removed)',
url='www.erikbethke.com',
py_modules=['mahjong','background','board','tile','textBox']
)

shutil.copytree('data', 'dist/data')
shutil.copyfile('freesansbold.ttf', 'dist/freesansbold.ttf')
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top