新建一个模块.py文件比如叫setup.py, 在一下代码的BuildExe中修改相关的参数即可,根据注释引导即可
#!python
# -*- coding: gb2312 -*-
# 这个脚本专为pygame优化,使用py2exe打包代码和资源至dist目录
#
# 使用中若有问题,可以留言至:
# http://eyehere.net/2011/python-pygame-novice-professional-py2exe/
#
# 安装需求:
# python, pygame, py2exe 都应该装上
# 使用方法:
# 1: 修改此文件,指定需要打包的.py和对应数据
# 2: python pygame2exe.py
# 3: 在dist文件夹中,enjoy it~
try:
from distutils.core import setup
import py2exe, pygame
from modulefinder import Module
import glob, fnmatch
import sys, os, shutil
except ImportError, message:
raise SystemExit, "Sorry, you must install py2exe, pygame. %s" % message
# 这个函数是用来判断DLL是否是系统提供的(是的话就不用打包)
origIsSystemDLL = py2exe.build_exe.isSystemDLL
def isSystemDLL(pathname):
# 需要hack一下,freetype和ogg的dll并不是系统DLL
if os.path.basename(pathname).lower() in ("libfreetype-6.dll", "libogg-0.dll", "sdl_ttf.dll"):
return 0
return origIsSystemDLL(pathname)
# 把Hack过的函数重新写回去
py2exe.build_exe.isSystemDLL = isSystemDLL
# 这个新的类也是一个Hack,使得pygame的默认字体会被拷贝
class pygame2exe(py2exe.build_exe.py2exe):
def copy_