embed resources into exe with py2exe for pygame

This is the place for queries that don't fit in any of the other categories.

embed resources into exe with py2exe for pygame

Postby metulburr » Fri May 23, 2014 1:20 pm

I have been just manually copying resources to wherever the exe is before, so i have been researching how to embed those same resources inside the exe, so that the exe may be self reliant on itself. I havent really found solutions online (at least what i can figure out). The only thing i have come across (to actually get to work) is copying the resources to the directory

setup.py
Code: Select all
import os
import sys
import py2exe
from distutils.core import setup
#import glob
import shutil
import time

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

'''
def find_data_files(source,patterns,target=None):
    if not target:
        target=source
    if glob.has_magic(source) or glob.has_magic(target):
        raise ValueError("Magic not allowed in src, target")
    ret = {}
    for pattern in patterns:
        pattern = os.path.join(source,pattern)
        for filename in glob.glob(pattern):
            if os.path.isfile(filename):
                targetpath = os.path.join(target,os.path.relpath(filename,source))
                path = os.path.dirname(targetpath)
                ret.setdefault(path,[]).append(filename)
    return sorted(ret.items())
'''


sys.argv.append('py2exe')
setup(
    options={
        'py2exe': {
            'bundle_files': 1,
            'compressed': True,
            'dll_excludes': ['w9xpopen.exe'], #do not inlcude w9xpopen.exe
        }
    },
    windows=[{'script': "game.py"}],
    zipfile=None,)
'''
data_files = find_data_files(
    'resources',[
        'graphics/*',
        'music/*',
        'fonts/*',
        'sound/*',
    ]
),
'''

shutil.copytree('resources', 'dist/resources')
shutil.rmtree('build')
name = time.strftime("%Y%m%d-%H%M%S", time.localtime())
os.rename('dist', 'exe build {}'.format(name))

The code docstring'd out is what i came across their tutorials, but data_files option is just copying the resource directory into the dist directory. Not embedding it into the exe. So i commented it all out and jhust added shutil.copytree() to mimic that as theirs seems redundant and complex just to copy the resources over.

I came across http://stackoverflow.com/questions/1939 ... ccess-them
and i really have not idea how this is suppose to work. On their website, i dont really see anything related to embedding resources within the exe.
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1470
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests