Fold All / Expand All

2008年1月26日 星期六

PythonCard與py2exe

拿原本跑wxPython的setup.py去跑,dist是會產生出來,但是一跑就error啦。Traceback (most recent call last):
File "main.py", line 59, in <module>
File "PythonCard\model.pyo", line 366, in __init__
File "PythonCard\resource.pyo", line 45, in __init__
File "PythonCard\util.pyo", line 39, in readAndEvalFile
TypeError: coercing to Unicode: need string or buffer, NoneType found

說明請見py2exe的wiki:PythonCardSetup
簡單講,就是沒有把resource檔(resc.py)與components複製到,所以把setup.py稍微修改一下即可。

以下是目前pyLyricRetriever的setup.py (not refined)
from distutils.core import setup
import py2exe

manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
version="0.64.1.0"
processorArchitecture="x86"
name="Controls"
type="win32"
/>
<description>myProgram</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>
"""

"""
installs manifest and icon into the .exe
but icon is still needed as we open it
for the window icon (not just the .exe)
changelog and logo are included in dist
"""

import os
# find pythoncard resources, to add ad 'data_files'
pycard_resources = []
for filename in os.listdir('.'):
if filename.find('.rsrc.') > -1:
pycard_resources += [filename]

# includes for py2exe
includes = []
for comp in ['button', 'image', 'staticbox', 'statictext',
'textarea', 'textfield', 'passwordfield']:
includes += ['PythonCard.components.' + comp]
print 'includes', includes

setup(
windows = [
{
"script": "main.py",
"icon_resources": [(1, "lyric_ico.ico")],
"other_resources": [(24,1,manifest)],
}
],
options = {
"py2exe": {
"optimize": 2,
"compressed": 1,
"includes": includes,
}
},
data_files = [('', ['lyric_ico.ico'] + pycard_resources)]
)

沒有留言: