A guide for using development PyInstaller + PyGame on Windows 7.

4,017 views
Skip to first unread message

Cameron Seebach

unread,
May 8, 2012, 3:30:55 PM5/8/12
to pyins...@googlegroups.com
Hi Everybody!

I report with a great deal of happiness that the development version of PyInstaller works very well with the latest version of PyGame. One file game deployment is now a reality for me! Thank you so much. :)

I would add this to the "Supported Packages" page myself if I had the privileges. Here are the caveats:

I get an an unknown error when using System Fonts (pygame.font.SysFont). Rather than spend the time trying to figure out the error, (I have a hunch it is something to do with paths relative to a C runtime), simply bundle a font with your game and use pygame.font.Font instead.

The rest of these workarounds require that you build and modify your .spec file yourself. If you don't know how to do this already, in short, use utils\Makespec.py and utils\Build.py. The manual has good pointers on these.

To bundle art resources with your game, the easiest way I've found is to insert a Tree entry with your art directory into the right place in the .spec file. For --onefile, that's the EXE entry. For --onedir, that's COLLECT.

Tree('\\game\\res', prefix="res\\")

When bundling resources (sprites, sounds, music) with your game, I run paths through the following code to make sure the right paths are found both when developing and when in deployment. Note this is only necessary for the --onefile distribution, which I prefer.

def resource_path(relative):
    if hasattr(sys, "_MEIPASS"):
        return os.path.join(sys._MEIPASS, relative)
    return os.path.join(relative)

Last, when I use the --noconsole option over here, PyInstaller thinks that I'm trying to build a Macintosh app, and sticks everything inside a "game.app" folder. This isn't really a problem, but if it annoys you, generate your .spec file without this option, and simply change the "console" argument to False inside EXE.

Thanks again for such a wonderful project. I'm over the moon! :D

-Cameron

Hartmut Goebel

unread,
May 9, 2012, 4:20:14 AM5/9/12
to pyins...@googlegroups.com
Am 08.05.2012 21:30, schrieb Cameron Seebach:
> I would add this to the "Supported Packages" page myself if I had the
> privileges.

Please tell me you username you registered for at our trac. So I can
give you contributor access.

If I understood you right, this is a recipe for how to get PyGame
running on Windows 7. So it should go to the Recipe section of the
wiki. Then in the "Supported Packages" add a hint to the recipe. Thanks.

--
Schönen Gruß - Regards
Hartmut Goebel
Dipl.-Informatiker (univ.), CISSP, CSSLP

Goebel Consult
Spezialist für IT-Sicherheit in komplexen Umgebungen
http://www.goebel-consult.de

Monatliche Kolumne: http://www.cissp-gefluester.de/
Goebel Consult ist Mitglied bei http://www.7-it.de


Giovanni Bajo

unread,
May 10, 2012, 8:12:03 PM5/10/12
to pyins...@googlegroups.com
Hi Cameron,

what part of this is specific to PyGame? It looks like everything is covered by this:

isn't it?
-- 
Giovanni Bajo   ::  ra...@develer.com
Develer S.r.l.  ::  http://www.develer.com

My Blog: http://giovanni.bajo.it





Christian Tismer

unread,
Oct 11, 2013, 5:30:06 AM10/11/13
to pyins...@googlegroups.com
Hi Giovanni, Cameron,

I agree that the info is basically exact and covered in the wiki.
But I think augmenting this with a full example and lots of comments what
every piece does is a good thing to have.

cheers - Chris
Reply all
Reply to author
Forward
0 new messages