基于pygame的象棋游戏四:打包成exe文件

 

有一个非常好用的python程序打包成可执行程序的工具,py2exe,使用它,需要编写一段脚本,如下所示。

setup.py
1 #!/usr/bin/env python
2 # -*- coding: UTF-8 -*-
3  
4  from distutils.core import setup
5  import sys
6
7  # 产品版本
8  revision = "1.0.0.0"
9
10  if sys.platform == 'win32':
11 # 检查命令行参数
12   if len(sys.argv) == 1:
13 sys.argv.append("py2exe")
14 sys.argv.append("-q")
15
16 from py2exe.build_exe import py2exe
17 setup(
18 platforms = ['Windows'],
19 version = revision,
20 description = "Chinese chess",
21 name = "Chinese chess",
22 long_description = "Chinese chess",
23 url = "www.cnblogs.com/stuarts",
24 maintainer = 'stuarts',
25 maintainer_email = 'stuarts740@gmail.com',
26 zipfile = None, # 不生成library.zip
27 windows = [
28 {
29 "script": "ChsChess.py",
30 "icon_resources": [
31 (0, "ChsChess.ico"),
32 ]
33 }
34 ],
35 data_files = [('BMP', \
36 [ \
37 r'.\BMP\b_bing.bmp', \
38 r'.\BMP\b_jiang.bmp', \
39 r'.\BMP\b_ju.bmp', \
40 r'.\BMP\b_ma.bmp', \
41 r'.\BMP\b_pao.bmp', \
42 r'.\BMP\b_shi.bmp', \
43 r'.\BMP\b_xiang.bmp', \
44 r'.\BMP\curPos.bmp', \
45 r'.\BMP\ground.bmp', \
46 r'.\BMP\r_bing.bmp', \
47 r'.\BMP\r_jiang.bmp', \
48 r'.\BMP\r_ju.bmp', \
49 r'.\BMP\r_ma.bmp', \
50 r'.\BMP\r_pao.bmp', \
51 r'.\BMP\r_shi.bmp', \
52 r'.\BMP\r_xiang.bmp', \
53 ] \
54 )],
55 options = {
56 "py2exe":{
57 "compressed" : 1,
58 "includes" : ["sip"],
59 "optimize" : 2,
60 "bundle_files": 1 # python, Qt等dll放入library
61 },
62 }
63 )
64

 

 

打包后,生成了依赖于MFC库MSVCR71.dll的可执行文件,以及图片文件夹。

 

这样,象棋游戏就可以在没有安装python的环境中运行了。

 

打包之后的截图:

posted @ 2010-06-09 20:33  stuarts  Views(1244)  Comments(0Edit  收藏  举报