I found the solution in part. First, modify your setup.py like this:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
PROGRAM_DAT = open('program.dat').read()
CLIENT_SECRETS = open('client_secrets.json').read()
setup(windows=[{'script': "program.py",
'other_resources': [
(u'PROGRAM_DAT', 1, PROGRAM_DAT),
(u'CLIENT_SECRETS', 2, CLIENT_SECRETS)
]
}],
options = {'py2exe': {'bundle_files': 1, 'compressed': True, "includes" : ['apiclient','httplib2','oauth2client',
'uritemplate']}
},
zipfile = None
)
If you want to build console application, simply change setup(windows=
on setup(console=
.
In program.py you can load resources like this:
import win32api
from StringIO import StringIO
datfile = StringIO( win32api.LoadResource(0, u'PROGRAM_DAT', 1))
print datfile.getvalue()
secrets = StringIO( win32api.LoadResource(0, u'CLIENT_SECRETS', 2))
print secrets.getvalue()
But there is no way to modify program.exe from program.exe. To save your changes in embedded program.dat, you will need another exe-file. Then, you can use win32api.BeginUpdateResource
, win32api.UpdateResource
and win32api.LoadResource
functions.